How It Works#
The retriever service translates user queries into vector similarity searches and returns ranked metadata-rich results. It separates backend-independent orchestration from backend-specific vector store implementations.
Architecture Summary#
Core layers#
API layer (
src/main.py): validates requests, exposes/health,/ready,/query, and/capabilities/filtersBatch orchestration (
src/retriever/batch_executor.py): executes query list with error isolationQuery execution (
src/retriever/service.py): normalizes filters, builds backend-native pushdown filters, calls the selected vector backend, and applies fallback filteringBackend registry (
src/retriever/backends/registry.py): resolves backend modules and filter translators dynamicallyBackend implementation (
src/retriever/backends/<name>/backend.py): creates backend vector store clientBackend filter translation (
src/retriever/backends/<name>/filters.py): translates query filters into backend-native syntax
---
config:
theme: dark
---
flowchart TB
Client(["Client"])
subgraph API["API layer — src/main.py"]
Endpoints["/health · /ready · /query · /capabilities/filters"]
end
subgraph Orchestration["Batch orchestration"]
Batch["execute_batch()<br/>bounded concurrency, error isolation"]
end
subgraph Execution["Query execution"]
Service["execute_single_query()<br/>filter normalization, pushdown build,<br/>fetch_k sizing, fallback filtering"]
end
subgraph Registry["Backend registry"]
Reg["resolves backend + filter modules<br/>by RETRIEVER_BACKEND setting"]
end
subgraph Backend["Backend implementation"]
Impl["backend.py: vector store client"]
Filt["filters.py: native filter translation"]
end
Embedding["Embedding client<br/>src/retriever/embedding_client.py"]
Store[("Vector store<br/>VDMS · Milvus · PGVector · FAISS")]
Client --> API --> Orchestration --> Execution
Execution --> Registry --> Backend
Execution -.image query.-> Embedding
Embedding --> Store
Embedding --> Registry
Backend --> Store
Request flow#
Client sends
POST /querywith a list of query blocks.Service validates schema and filter operators.
Service detects query modality: text (
query) or image (image).Service normalizes the primary
wherecontract plus compatibility aliases (tags,time_filter,filters).Backend-specific pushdown filters are built from the safe subset of predicates.
Service computes candidate retrieval size (
fetch_k), including over-fetch when pushdown is partial or absent.For text queries, the selected vector store executes similarity search with score. For image queries, the service computes the image embedding via the embedding API and performs vector search by embedding.
Service applies fallback filtering against returned metadata for consistency across backends.
Results are sorted and returned as
BatchQueryResponsewith partial errors when needed.
---
config:
theme: dark
---
sequenceDiagram
autonumber
participant Client
participant API as API layer<br/>(main.py)
participant Batch as Batch executor
participant Service as Query service
participant Embed as Embedding client
participant Backend as Vector backend
Client->>API: POST /query (query blocks)
API->>API: Validate schema & filter operators
API->>Batch: execute_batch(requests)
Batch->>Service: execute_single_query(request) [per block, bounded concurrency]
Service->>Service: Detect modality (text vs image)
Service->>Service: Normalize where + aliases (tags, time_filter, filters)
Service->>Service: Build pushdown filter (backend-native)
Service->>Service: Compute fetch_k (+ over-fetch if pushdown partial)
alt text query
Service->>Backend: similarity_search_with_score(query, fetch_k, filter)
else image query
Service->>Embed: compute image embedding
Embed-->>Service: embedding vector
Service->>Backend: similarity_search_with_score_by_vector(embedding, fetch_k, filter)
end
Backend-->>Service: candidate results + scores
Service->>Service: Apply fallback filtering on metadata
Service->>Service: Sort & trim to top_k
Service-->>Batch: QueryResultBlock (or QueryError)
Batch-->>API: results + partial errors
API-->>Client: BatchQueryResponse
Pushdown and fallback model#
Pushdown stage: backend-native filter payload is built from pushdown-safe predicates.
Fallback stage: full normalized
wheretree is evaluated in service code on retrieved candidates.
Fallback evaluation is authoritative for final inclusion. Over-fetch is used to increase the candidate pool before fallback when the service detects that backend pushdown may be incomplete.
Why registry with backend folders#
The backend registry lets the service support multiple vector stores without backend conditionals spread across business logic. Each backend owns:
connection/client setup
readiness behavior
filter translation semantics
This keeps onboarding of new backends localized and predictable.
Supported backend filter styles#
VDMS: list-based filter expressions
Milvus: SQL-like
exprstringPGVector: Mongo-style filter document
FAISS: dict-style metadata filters (Mongo-like operators)