Skip to main content

Faiss

Langchain vector store for FAISS. Supports save/load to disk.

Install

pip install langchain-faiss-vectorstore

or

uv add langchain-faiss-vectorstore

API Reference

__init__

def __init__(
    self,
    embedding_function: Embeddings | None = None,
    index: faiss.Index | None = None,
    **kwargs,
)
Parameter Type Description
embedding_function Embeddings | None Embedding function used to embed queries and texts (e.g., FastEmbedEmbeddings).
index faiss.Index | None Optional pre-built FAISS index. If None, creates an IndexIDMap wrapping IndexFlatL2 with dimension 0 (auto-sized on first add_texts).

from_texts

def from_texts(
    cls,
    texts: list[str],
    embedding: Embeddings | None = None,
    metadatas: list[dict] | None = None,
    ids: list[str] | None = None,
    **kwargs,
) -> Faiss
Parameter Type Description
texts list[str] Texts to index.
embedding Embeddings | None Embedding function.
metadatas list[dict] | None Optional metadata dicts, one per text.
ids list[str] | None Optional document IDs. Auto-generated if not provided.

Returns: Faiss — a new vector store with the texts indexed.


add_texts

def add_texts(
    self,
    texts: list[str],
    metadatas: list[dict] | None = None,
    ids: list[str] | None = None,
    **kwargs,
) -> list[str]
Parameter Type Description
texts list[str] Texts to add to the index.
metadatas list[dict] | None Optional metadata dicts, one per text. Defaults to {}.
ids list[str] | None Optional document IDs. Auto-generated if not provided.

Returns: list[str] — the IDs of the added texts.


delete

def delete(
    self,
    ids: list[str] | None = None,
    **kwargs,
) -> bool | None
Parameter Type Description
ids list[str] | None List of document IDs to remove.

Returns: bool — True if deletion succeeded. Raises ValueError if ids is None.


similarity_search

def similarity_search(
    self,
    query: str,
    k: int = 4,
    **kwargs,
) -> list[Document]
Parameter Type Description
query str Query text.
k int Number of documents to return. Default 4.

Returns: list[Document] — documents most similar to the query, ordered by L2 distance (ascending).


similarity_search_with_score

def similarity_search_with_score(
    self,
    query: str,
    k: int = 4,
    **kwargs,
) -> list[tuple[Document, float]]
Parameter Type Description
query str Query text.
k int Number of documents to return. Default 4.

Returns: list[tuple[Document, float]] — tuples of (Document, L2_distance). Lower distance = more similar.


save_local

def save_local(
    self,
    folder_path: str | Path,
) -> None
Parameter Type Description
folder_path str | Path Directory to save the index and document data. Created if it doesn't exist.

Writes two files into folder_path:

  • index.faiss — the serialized FAISS index.
  • docs.json — document contents and metadata.

load_local

def load_local(
    cls,
    folder_path: str | Path,
    embedding_function: Embeddings,
    allow_dangerous_deserialization: bool = False,
) -> Faiss
Parameter Type Description
folder_path str | Path Directory containing index.faiss and docs.json.
embedding_function Embeddings Embedding function to use for future queries.
allow_dangerous_deserialization bool Safety flag (acknowledged). Default False.

Returns: Faiss — a restored vector store instance.

Metadata

Release files for langchain-faiss-vectorstore 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-faiss-vectorstore 0.1.0
File Size Uploaded
langchain_faiss_vectorstore-0.1.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-faiss-vectorstore 0.1.0
File Interpreter ABI Platform
langchain_faiss_vectorstore-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / langchain_faiss_vectorstore-0.1.0.tar.gz

Download URL langchain_faiss_vectorstore-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bcf36cfd2de88038b5e8e22353f0f84ad2f633f7553f0434829f99279fbf1876
BLAKE2b-256 checksum
How to use checksums
e8ba0f4a68844f9dab7e3d5c8f2a84dbaad00f4a35232f0d8cfedc4c58f43434
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.17

Release files / langchain_faiss_vectorstore-0.1.0-py3-none-any.whl

Download URL langchain_faiss_vectorstore-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75ea19ae243de06f35f586b9d2c74d917013b7b90b675eb6453a124bc2856947
BLAKE2b-256 checksum
How to use checksums
f4767aab84a4355924ef53258624ae7a31da4fa0950457ade50762729ec17600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.17

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page