langchain.chains.ConversationalRetrievalChain() fails with FAISS store
Tried to wire ConversationalRetrievalChain with a FAISS vector store. The constructor crashed.
ValueError: Provided embeddings are incompatible with stored index dimension
Embeddings built with sentence-transformers/all-MiniLM-L6-v2
, dim 384. LangChain 0.0.286, faiss‑cpu 1.7.4, Python 3.11 on macOS.
Checked index.d
size; confirmed 384. The error came from LangChain pulling the default OpenAI embeddings (dim 1536) because I forgot to pass the original embedding object to as_retriever()
.
Working code:
retriever = vector.as_retriever(search_type="similarity", search_kwargs={"k":4}, embeddings=embed)
chain = ConversationalRetrievalChain.from_llm(llm, retriever=retriever)
After passing the same embedding model the chain built and returned results.
If you still hit dimension mismatch delete index.faiss
and rebuild; FAISS can store the wrong size if the first insert uses a different model.