Course Content
LangChain Mastery
7 sections · 109 lessons
How do you save and load a vector store in LangChain?
What you need to know
Three kinds of persistence
| Kind | Examples | Save | Load |
|---|---|---|---|
| In-memory only | InMemoryVectorStore | dump(path) to a file | InMemoryVectorStore.load(path, embedding) |
| Local files | FAISS, Chroma | FAISS: save_local; Chroma: automatic | Reopen with the same embedding |
| Server | pgvector, Qdrant, Pinecone | Automatic on write | Reconnect with URL and collection name |
FAISS
1from langchain_community.vectorstores import FAISS23vs = FAISS.from_documents(chunks, embeddings)4vs.save_local("indexes/hr_faiss") # writes index.faiss + index.pkl56vs = FAISS.load_local(7 "indexes/hr_faiss", embeddings,8 allow_dangerous_deserialization=True,9)index.faiss holds the vectors; index.pkl holds the documents and id mapping, saved with Python pickle. Unpickling a file from an untrusted source can run arbitrary code. That is why LangChain makes you opt in with the flag. Only load indexes your own pipeline built.
Chroma
1from langchain_chroma import Chroma23vs = Chroma(4 collection_name="hr_policies",5 embedding_function=embeddings,6 persist_directory="./chroma",7)The same constructor creates the collection the first time and reopens it later.
What to store with the index
A small index_meta.json next to the index: embedding model and version, vector dimensions, chunk_size, chunk_overlap, splitter, and the date built. Check it at startup.
A real-life example
A travel-booking company runs its "visa rules" assistant on 8 small pods. Each pod used to rebuild a FAISS index from 3,000 PDFs at startup — about 6 minutes and around 40,000 embedding calls per restart, multiplied by 8 pods.
They move indexing to a nightly job. The job builds the FAISS index once, calls save_local, writes index_meta.json, and uploads the folder to object storage. Pods download and load_local in about 4 seconds. At startup each pod compares index_meta.json with its configured embedding model and refuses to start on a mismatch.
A year later, as the corpus reaches millions of chunks and several services need it, they move to pgvector. There is no save or load step any more; the nightly job writes straight into Postgres.
Follow-up questions to expect
- "Why does FAISS need that dangerous flag?" — Because part of the saved index is a pickle, and loading a pickle can execute code. The flag makes you confirm you trust the file.
- "How do you update a saved FAISS index?" — Load it,
add_documentsordelete(ids=...), thensave_localagain; for frequent changes, use a server store. - "Can two processes write the same local Chroma directory?" — Not safely at scale. Run Chroma as a server, or use a real database.