NeedleDB: A Generative-AI Based System for Accurate and Efficient Image Retrieval using Complex Natural Language Queries

Mahdi Erfanian, Abolfazl AsudeharXiv 2026

TL;DR

NeedleDB is an open-source, deployment-ready database system that flips traditional text-to-image retrieval on its head. Instead of relying on contrastive models like CLIP, which struggle with complex or compositional text, NeedleDB uses generative AI to synthesize "guide images" from the query, transforming the problem into a highly accurate image-to-image search. It achieves up to a 93% improvement in Mean Average Precision (MAP) over state-of-the-art baselines while maintaining sub-second query latencies.

What Problem Does This Paper Address?

When searching large image collections using natural language, state-of-the-art systems typically rely on contrastive learning models like CLIP. These models map both text and images into a shared embedding space, making nearest-neighbor search straightforward.

While this works well for simple object-detection queries (e.g., "traffic light"), it falls apart when queries become complex, compositional, or nuanced. For instance, if you search for "a person walking with a cane" or "a cat wearing a tiny cowboy hat sitting on a stack of books," contrastive models often fail because they struggle to capture spatial relationships, specific attributes, and abstract concepts. They suffer from a "bag-of-words" bias, frequently returning images that contain the individual elements but completely miss the requested composition or context.

Figure 1: Top-3 results on BDD100K [19] for queries of in- creasing complexity. CLIP returns relevant results only for the simple query (a), whereas NeedleDB retrieves relevant images for all three queries using just 2 guide images (Re- alVisXL) and 2 embedders (EVA, RegNet)

Methods

The core insight of NeedleDB is to reframe text-to-image retrieval as an image-to-image retrieval problem.

Figure 2: Architecture of the NeedleDB system. A query flows from the user layer through the backend’s multi-stage inference pipeline to the infrastructure services.

The system processes queries through an optimized two-stage inference pipeline:

  1. Guide Image Generation & Multi-Embedder Search: When a user inputs a text query, NeedleDB's Generator Hub uses fast text-to-image foundation models (like SD-Turbo or DALL-E 3) to generate $m$ synthetic "guide images." Because it utilizes locally hosted latent-consistency models (SD-Turbo) running at 512×512 resolution with only 1–4 inference steps, this generation happens in milliseconds. Each synthetic image is then processed by an ensemble of $l$ vision-only embedders (such as EVA, RegNet, or DINO), and a $k$-NN search is executed against a Milvus vector database using an efficient HNSW index.
  2. Weighted Rank Aggregation: The results from all $m \times l$ independent searches are combined using a weighted reciprocal-rank fusion strategy. To prevent poorly generated guide images from ruining the results, an anomaly detection module based on the Local Outlier Factor (LOF) filters out low-quality synthetic images before aggregation.

On the system side, NeedleDB features a modular microservice architecture backed by PostgreSQL (for metadata) and Milvus (for vector storage). It includes a full-featured command-line interface (needlectl) and a browser-based React Web UI.

Datasets

The authors evaluated NeedleDB across several standard computer vision and compositional language benchmarks:

  • Object Detection: Caltech256, COCO, LVIS (a large vocabulary dataset with ~120K images and 1000+ categories), and BDD100K (a diverse driving dataset).
  • Complex Natural Language Queries: COLA, Winoground, SentiCap, and NoCaps benchmarks were used to test the system's understanding of complex text descriptions, spatial ordering, and compositionality.

Key Insights and Ideas

  • Generative Models as Translators: Generative AI models are remarkably adept at translating complex textual semantics into the visual domain. Leveraging them to create visual "anchors" (guide images) bypasses the limitations of aligning complex text embeddings directly with real-world image embeddings.
  • Ensembling Defeats Bias: Relying on a single vision model introduces specific architectural biases. By querying an ensemble of distinct vision-only embedders (like EVA and RegNet) and fusing their rankings, NeedleDB mitigates individual model weaknesses.
  • The Power of Local Latent-Consistency Models: Using heavy APIs like DALL-E 3 is too slow for real-time database queries. NeedleDB proves that locally hosted, highly optimized models like SD-Turbo can deliver the required visual quality within milliseconds, making generative retrieval practical.

Key Results

  • Accuracy Leaps: NeedleDB significantly outperformed all eight baselines. On "hard" queries (where CLIP's Average Precision was less than 0.5), NeedleDB achieved a +73% relative gain on Caltech256 and a +93% relative gain on LVIS compared to the second-best baseline.
  • Compositional Mastery: On the challenging Winoground and COLA benchmarks, NeedleDB achieved the highest Pairing Accuracy (0.593 and 0.631, respectively), proving its superior grasp of spatial and attribute relationships.
  • Sub-Second Latency: Using its optimized "Fast" pipeline profile (SD-Turbo + EVA + RegNet), NeedleDB processed queries end-to-end on the 100K-image LVIS dataset in just 0.203 seconds (0.136s for image generation and 0.053s for multi-embedder vector search).

Limitations and Future Work

While NeedleDB represents a major step forward, its performance is inherently bound by the capabilities of the underlying text-to-image generator; if the generator completely misinterprets a highly abstract text query, the downstream image search will suffer.

The authors outlined two main avenues for future work:

  1. Extending the generative retrieval framework beyond static images to handle multi-modal audio and video data.
  2. Improving the alignment of foundation models specifically to handle highly complex, edge-case compositional queries even more reliably.

Summary updated

BibTeX
@misc{erfanian2026needledb,
  author = {Mahdi Erfanian and Abolfazl Asudeh},
  title = {{NeedleDB: A Generative-AI Based System for Accurate and Efficient Image Retrieval using Complex Natural Language Queries}},
  year = {2026},
  eprint = {2603.27464},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.27464},
}
Figure