Skip to main content
A vector store answers “give me chunks similar to this query.” A retriever is the layer above that — same job, more knobs. Cognis ships eight retrievers; most apps use one or two, occasionally combined. They all share the same shape: Runnable<String, Vec<Document>>.

Pick a retriever

For LLM-driven retrievers (multi-query expansion, contextual compression, query decomposition), see also cognis::retrievers::* — those live in the umbrella because they hold a Client.

Quick example

Every retriever returns Vec<Document>, ready to fold into a prompt or pass to the next stage.

Hybrid retrieval

Combine dense (vector) and sparse (BM25) retrieval for the best of both:
Weights are normalized; the result merges and re-ranks.

Reranking

After initial retrieval, a cross-encoder can re-rank top-K candidates by direct query-document scoring:
Cognis ships CrossEncoder as a trait; bring your own scorer (a small reranker model, a heuristic, or a remote service).

Filtering and metadata

Retrievers respect the metadata filters their underlying store supports:

Composing in a chain

Retrievers are Runnables, so they pipe like anything else:
The full RAG pattern lives in Patterns → Code Q&A.

How it works

  • Retrievers compose. Layer caching, reranking, and translation by piping retrievers together.
  • top_k is a request, not a guarantee. A store with fewer than k matching docs returns what it has.
  • Filters happen at the store layer when possible. When the underlying backend can do it (Qdrant, Pinecone, Weaviate), it does — no scan-then-filter penalty.
  • Caching is a thin shell. CachingRetriever keys on the query string; if your retriever takes a filter, two different filters with the same query are different cache entries.

See also

Reranking and compression

Cross-encoders, compressors, long-context reorder.

Indexing pipeline

Make sure the store has the right docs.

Patterns → Code Q&A

A complete retriever-driven Q&A.