fastrag.retrieval.vector#

VectorRetriever: dense similarity search over a VectorStore.

Classes

VectorRetriever(*, vector_store, embedder)

Dense similarity search: the base retriever every other one over-fetches from.

class fastrag.retrieval.vector.VectorRetriever(*, vector_store, embedder)[source]#

Bases: Retriever

Dense similarity search: the base retriever every other one over-fetches from.

Holds its collaborators without owning their lifecycles: the caller opens vector_store (async with MilvusVectorStore(...) as vector_store:) and this retriever never opens or closes it. embedder is used only for its embed() method — never run as a pipeline step, never cached, never batched — so a single query embeds as one call.

async with MilvusVectorStore(url=MILVUS_URI) as vector_store:
    retriever = VectorRetriever(
        vector_store=vector_store,
        embedder=Model2VecEmbedder(model=EMBEDDING_MODEL),
    )
    documents = await retriever.retrieve("What is AgrospAI?", k=5)
Parameters:
  • vector_store (VectorStore) – The collection to search. Opened by the caller.

  • embedder (Embedder) – Embeds the query text with the same model the collection was indexed with.

async retrieve(query, *, k=5)[source]#

Embed query and return the k nearest documents, best first.

Parameters:
Return type:

list[Document]