Replies: 2 comments 4 replies
-
@kwunhang Hello there! I'm a bot designed to help you solve bugs, answer questions, and become a contributor. Feel free to ask me anything while waiting for a human maintainer. To define a custom index for the FAISS vector store using the Here is an example of how you can do this: from langchain_community.embeddings.openai import OpenAIEmbeddings
from langchain_community.vectorstores import FAISS
import faiss
# Define your custom index
dimension = 128 # Example dimension, set this to the dimension of your embeddings
custom_index = faiss.IndexFlatL2(dimension)
# Create embeddings
embeddings = OpenAIEmbeddings()
texts = ["FAISS is an important library", "LangChain supports FAISS"]
embedded_texts = embeddings.embed_documents(texts)
# Use the __from method to create the FAISS vector store with the custom index
faiss_store = FAISS.__from(
texts=texts,
embeddings=embedded_texts,
embedding=embeddings,
index=custom_index # Pass your custom index here
)
# Now you can use faiss_store as needed By using the |
Beta Was this translation helpful? Give feedback.
-
If you are still interested in custom langchain faiss index, I made a custom backend enabling both transparent compression (when saving to file) as well as binary embeddings (smaller, faster, usually negligible loss) for my personal rag library called wdoc (for now it's in the dev branch, in wdoc/utils/customs/binary_faiss_vectorstore.py). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I am using the FAISS of Langchain library. I found there are multiple indexes is support in faiss.
https://github.com/facebookresearch/faiss/wiki/Faiss-indexes
And I also found there is a "index" parameter in FAISS init function in langchain library. Now my code is using the function "FAISS.from_documents" and I want to self define the index for it. But I meet a error:
FAISS.init() got multiple values for argument 'index'
May I please ask is there any other way is suggested if I want to defined the index in such case?
System Info
FAISS.init() got multiple values for argument 'index'
Beta Was this translation helpful? Give feedback.
All reactions