ractogateway.rag.stores.faiss_store

FAISS vector store (lazy import).

Install with: pip install ractogateway[rag-faiss]

class ractogateway.rag.stores.faiss_store.FAISSStore(dimension=None, index_type='flat_ip')[source]

Bases: BaseVectorStore

Vector store backed by Facebook AI Similarity Search (FAISS).

Stores embeddings in a flat L2 or cosine (Inner Product) index. All data is in-memory; call save() / load() to persist.

Parameters:
  • dimension (int | None) – Embedding dimension. Inferred from the first add() call if None.

  • index_type (str) – "flat_l2" or "flat_ip" (inner product / cosine when normalised).

add(chunks)[source]

Add chunks (with embeddings) to the store.

Parameters:

chunks (list[Chunk]) – Chunks to index. Each chunk must have a non-None embedding.

Raises:

ValueError – If any chunk has embedding=None.

Return type:

None

search(embedding, top_k=5, filters=None)[source]

Search for the top_k most similar chunks.

Parameters:
  • embedding (list[float]) – Query embedding vector.

  • top_k (int) – Number of results to return.

  • filters (dict[str, Any] | None) – Optional metadata filters (store-specific format).

Return type:

list[RetrievalResult]

Returns:

list[RetrievalResult] – Ranked list of results (rank 1 = most similar).

delete(chunk_ids)[source]

Remove chunks with the given IDs from the store.

Return type:

None

clear()[source]

Remove all chunks from the store.

Return type:

None

count()[source]

Return the total number of indexed chunks.

Return type:

int

save(path)[source]

Persist the FAISS index to path.index and chunks to path.chunks.

Return type:

None

load(path)[source]

Load a previously saved index from path.

Return type:

None