windlass.providers.vectordb.faiss¶
faiss
¶
FAISS vector store.
FAISS gives you approximate nearest-neighbour search over millions of vectors on a single machine, with no server to run. Windlass keeps chunk payloads in a side-table (FAISS stores vectors only) and maps between FAISS's integer ids and Windlass chunk ids.
Install with::
pip install "windlass[faiss]"
Example
from windlass import Windlass # doctest: +SKIP store = Windlass.vectordb("faiss", dimensions=384, # doctest: +SKIP ... persist_path="./index") # doctest: +SKIP
FaissVectorStore
¶
FaissVectorStore(
*,
collection: str = "windlass",
dimensions: int | None = None,
metric: str = "cosine",
index_type: str = "flat",
nlist: int = 100,
nprobe: int = 10,
persist_path: str | None = None,
**config: Any
)
Bases: VectorStore
Vector store backed by a FAISS index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
str
|
Logical name, used for the persistence filenames. |
'windlass'
|
dimensions
|
int | None
|
Vector length. Required — FAISS allocates the index up front and cannot infer it. |
None
|
metric
|
str
|
|
'cosine'
|
index_type
|
str
|
|
'flat'
|
nlist
|
int
|
Number of IVF clusters. Ignored for other index types. |
100
|
nprobe
|
int
|
How many IVF clusters to scan at query time. Higher means better recall and slower search. |
10
|
persist_path
|
str | None
|
Directory to save the index and payload side-table to. |
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
ConfigurationError
|
When |
Performance
flat is exact and fast to about a million vectors. ivf needs at
least 39 * nlist vectors to train and is trained automatically on the
first write that has enough data. Searching an untrained IVF index falls
back to brute force rather than failing.
Source code in src\windlass\providers\vectordb\faiss.py
native
¶
aadd
async
¶
Insert or update chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
Sequence[Chunk]
|
Chunks with embeddings set. |
required |
Returns:
| Type | Description |
|---|---|
int
|
How many chunks were written. |
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If a chunk has no embedding. |
ProviderError
|
On dimension mismatch or a FAISS failure. |
Source code in src\windlass\providers\vectordb\faiss.py
adelete
async
¶
Delete by chunk id or metadata filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Sequence[str] | None
|
Chunk ids to remove. |
None
|
filters
|
MetadataFilter | None
|
Metadata constraints. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
How many chunks were removed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither argument is supplied. |
Source code in src\windlass\providers\vectordb\faiss.py
aclear
async
¶
Drop the index and rebuild it empty.
asearch
async
¶
asearch(
vector: Sequence[float],
k: int = 5,
*,
filters: MetadataFilter | None = None,
**kwargs: Any
) -> list[ScoredChunk]
Search the index.
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, applied after the ANN search. Windlass
over-fetches by a factor of :data: |
None
|
**kwargs
|
Any
|
Ignored. |
{}
|
Returns:
| Type | Description |
|---|---|
list[ScoredChunk]
|
Ranked hits. |
Source code in src\windlass\providers\vectordb\faiss.py
aget
async
¶
acount
async
¶
all_chunks
¶
Return every stored chunk, for building a companion lexical index.
apersist
async
¶
Save the index and payloads to :attr:persist_path.
Source code in src\windlass\providers\vectordb\faiss.py
save
¶
Write the FAISS index and its payload side-table to directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path
|
Destination directory, created if absent. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The directory written to. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
When the write fails. |
Source code in src\windlass\providers\vectordb\faiss.py
load
¶
Load an index previously written by :meth:save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path
|
Directory containing the index files. |
required |
Returns:
| Type | Description |
|---|---|
FaissVectorStore
|
|
Raises:
| Type | Description |
|---|---|
ProviderError
|
When the files are missing or unreadable. |