windlass.interfaces.vectordb¶
vectordb
¶
The vector-store interface.
A vector store persists chunks together with their embeddings and answers nearest-neighbour queries. FAISS, Chroma, Pinecone and the built-in in-memory store all sit behind this one class, so moving from a laptop prototype to a managed index is a one-word change in the builder.
Implementers override four coroutines: :meth:VectorStore.aadd,
:meth:VectorStore.asearch, :meth:VectorStore.adelete and
:meth:VectorStore.acount.
Example
from windlass.providers.vectordb.memory import InMemoryVectorStore from windlass.core.types import Chunk store = InMemoryVectorStore(dimensions=3) store.add([Chunk(content="hi", embedding=[1.0, 0.0, 0.0])]) 1 store.search([1.0, 0.0, 0.0], k=1)[0].chunk.content 'hi'
VectorStore
¶
VectorStore(
*,
collection: str = "windlass",
dimensions: int | None = None,
metric: str = "cosine",
persist_path: str | None = None,
name: str | None = None,
**config: Any
)
Bases: Component
Abstract vector database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
str
|
Name of the collection / index / namespace to use. |
'windlass'
|
dimensions
|
int | None
|
Vector dimensionality. Required by stores that must create an index up front; inferred on first write by those that can. |
None
|
metric
|
str
|
Similarity metric — |
'cosine'
|
persist_path
|
str | None
|
Where an on-disk store should keep its data. |
None
|
name
|
str | None
|
Component name for traces. |
None
|
**config
|
Any
|
Store-specific options. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
collection |
The active collection name. |
|
metric |
The configured similarity metric. |
|
supports_filters |
bool
|
Whether metadata filtering is pushed down to the store rather than applied client-side. |
supports_hybrid |
bool
|
Whether the store has native sparse+dense search. |
Example
Implementing a store means four methods::
class MyStore(VectorStore):
provider_name = "mine"
async def aadd(self, chunks): ...
async def asearch(self, vector, k=5, filters=None): ...
async def adelete(self, ids=None, filters=None): ...
async def acount(self): ...
Source code in src\windlass\interfaces\vectordb.py
aadd
abstractmethod
async
¶
Insert or update chunks.
Chunk ids are deterministic, so re-adding the same content must upsert rather than duplicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
Sequence[Chunk]
|
Chunks with :attr: |
required |
Returns:
| Type | Description |
|---|---|
int
|
How many chunks were written. |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If any chunk is missing its embedding. |
ProviderError
|
For store-side failures. |
Source code in src\windlass\interfaces\vectordb.py
asearch
abstractmethod
async
¶
asearch(
vector: Sequence[float],
k: int = 5,
*,
filters: MetadataFilter | None = None,
**kwargs: Any
) -> list[ScoredChunk]
Find the k nearest chunks to vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector
|
Sequence[float]
|
The query embedding. |
required |
k
|
int
|
How many results to return. |
5
|
filters
|
MetadataFilter | None
|
Metadata constraints. Stores without native filtering
should call :meth: |
None
|
**kwargs
|
Any
|
Store-specific search options. |
{}
|
Returns:
| Type | Description |
|---|---|
list[ScoredChunk]
|
Hits sorted by descending score, each with |
Source code in src\windlass\interfaces\vectordb.py
adelete
abstractmethod
async
¶
Delete chunks by id or by metadata filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Sequence[str] | None
|
Chunk ids to remove. |
None
|
filters
|
MetadataFilter | None
|
Metadata constraints selecting what to remove. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
How many chunks were deleted. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
Source code in src\windlass\interfaces\vectordb.py
acount
abstractmethod
async
¶
aget
async
¶
Fetch chunks by id.
The default returns []; stores that can look up by id should
override it. Parent-child retrieval relies on this to expand a matched
child into its parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Sequence[str]
|
Chunk ids to fetch. |
required |
Returns:
| Type | Description |
|---|---|
list[Chunk]
|
The chunks that exist, in whatever order the store returns them. |
Source code in src\windlass\interfaces\vectordb.py
aclear
async
¶
Remove every chunk from the collection.
The default deletes by listing ids, which is correct but slow; stores with a native truncate should override it.
Source code in src\windlass\interfaces\vectordb.py
apersist
async
¶
add
¶
search
¶
search(
vector: Sequence[float],
k: int = 5,
*,
filters: MetadataFilter | None = None,
**kwargs: Any
) -> list[ScoredChunk]
Blocking :meth:asearch.
Source code in src\windlass\interfaces\vectordb.py
delete
¶
count
¶
get
¶
clear
¶
persist
¶
validate_embeddings
staticmethod
¶
Assert that every chunk carries an embedding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
Sequence[Chunk]
|
Chunks about to be written. |
required |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
Naming the first chunk that is missing one. |
Source code in src\windlass\interfaces\vectordb.py
match_filters
staticmethod
¶
Evaluate a metadata filter client-side.
Supports plain equality plus the Mongo-style operators $eq, $ne,
$gt, $gte, $lt, $lte, $in, $nin, $contains
and $exists. Stores without native filtering use this so that filter
semantics are identical across every backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict[str, Any]
|
The chunk's metadata. |
required |
filters
|
MetadataFilter | None
|
The constraints. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the metadata satisfies every constraint. |
Example
VectorStore.match_filters({"year": 2024}, {"year": {"$gte": 2020}}) True VectorStore.match_filters({"tag": "a"}, {"tag": {"$in": ["b"]}}) False
Source code in src\windlass\interfaces\vectordb.py
rank
staticmethod
¶
Sort hits by descending score and assign 1-based ranks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hits
|
list[ScoredChunk]
|
Unordered hits. |
required |
Returns:
| Type | Description |
|---|---|
list[ScoredChunk]
|
The same objects, sorted and with |