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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_faiss_vectorstore-0.1.0.tar.gz.
File metadata
- Download URL: langchain_faiss_vectorstore-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcf36cfd2de88038b5e8e22353f0f84ad2f633f7553f0434829f99279fbf1876
|
|
| MD5 |
1c32c1824e69c8ebe8fd726db1385dba
|
|
| BLAKE2b-256 |
e8ba0f4a68844f9dab7e3d5c8f2a84dbaad00f4a35232f0d8cfedc4c58f43434
|
File details
Details for the file langchain_faiss_vectorstore-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_faiss_vectorstore-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75ea19ae243de06f35f586b9d2c74d917013b7b90b675eb6453a124bc2856947
|
|
| MD5 |
e844b591be4b56ed7d43d12163f77004
|
|
| BLAKE2b-256 |
f4767aab84a4355924ef53258624ae7a31da4fa0950457ade50762729ec17600
|