windlass.providers.retrievers.vector¶
vector
¶
Dense vector retrieval.
The standard semantic search path: embed the query with the same model that embedded the corpus, ask the vector store for nearest neighbours, return them.
Two refinements are built in:
- MMR (
diversity > 0) trades a little relevance for coverage, so you stop getting five near-identical chunks from the same page. - Parent expansion swaps matched child chunks for their larger parents when the pipeline uses parent-child chunking.
Example
from windlass.providers.embeddings.hash import HashEmbedder from windlass.providers.vectordb.memory import InMemoryVectorStore from windlass.core.types import Chunk emb = HashEmbedder(dimensions=128) store = InMemoryVectorStore(dimensions=128) chunks = [Chunk(content=t) for t in ["kittens purr", "engines roar"]] for c, v in zip(chunks, emb.embed([c.content for c in chunks])): ... c.embedding = v _ = store.add(chunks) r = VectorRetriever(embedder=emb, vectorstore=store) r.retrieve("kittens").hits[0].chunk.content 'kittens purr'
VectorRetriever
¶
VectorRetriever(
*,
embedder: Embedder | None = None,
vectorstore: VectorStore | None = None,
top_k: int = 5,
diversity: float = 0.0,
fetch_k: int | None = None,
expand_parents: bool = False,
parent_source: Any = None,
**config: Any
)
Bases: Retriever
Dense retrieval over a vector store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedder
|
Embedder | None
|
Model used to embed the query. Must be the same model that embedded the corpus. |
None
|
vectorstore
|
VectorStore | None
|
Where the vectors live. |
None
|
top_k
|
int
|
Default number of results. |
5
|
diversity
|
float
|
MMR strength in |
0.0
|
fetch_k
|
int | None
|
Candidates fetched before MMR narrows them. Defaults to
|
None
|
expand_parents
|
bool
|
Swap matched child chunks for their parents. Set automatically by the RAG builder when parent-child chunking is used. |
False
|
parent_source
|
Any
|
Object exposing |
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
When the embedder or vector store is missing. |
Performance
One embedding call plus one store query per retrieval. Enabling MMR
fetches fetch_k candidates and does O(fetch_k²) similarity work
in-process — negligible for the usual fetch_k ≤ 100.
Source code in src\windlass\providers\retrievers\vector.py
native
¶
aindex
async
¶
Embed and write chunks to the store.
Chunks that already carry an embedding are written as-is, so this is cheap to call on an already-embedded batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
Any
|
Chunks to index. |
required |
Returns:
| Type | Description |
|---|---|
int
|
How many chunks were written. |
Source code in src\windlass\providers\retrievers\vector.py
aretrieve_chunks
async
¶
aretrieve_chunks(
query: str, k: int, *, filters: MetadataFilter | None = None, **kwargs: Any
) -> list[ScoredChunk]
Embed the query and search the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query. |
required |
k
|
int
|
How many results to return. |
required |
filters
|
MetadataFilter | None
|
Metadata constraints, pushed down to the store. |
None
|
**kwargs
|
Any
|
Forwarded to the store's search method. |
{}
|
Returns:
| Type | Description |
|---|---|
list[ScoredChunk]
|
Ranked hits. |
Raises:
| Type | Description |
|---|---|
RetrievalError
|
When embedding or the store query fails. |