Hi,
I am using below code to use FAISS with langchain.
embedding=OpenAIEmbeddings(model="text-embedding-3-small")
# create vector db
vector_db=FAISS.from_texts(chunks, embedding=embedding)
# save vector db
vector_db.save_local(store_path)
I use below code to retrieve FAISS
# load vector db
vector_db=FAISS.load_local(store_path, OpenAIEmbeddings(model="text-embedding-3-small"))
I want to know, as I am calling embedding object 2 times
For create FAISS index
For load FAISS index
Does this cost me 2 times for embeddings?
Any alternatives if this cost me twice.
Thank you.
I’m not familiar with that specific library, but can’t you tell from logs how many times remote http calls are made to the API in any case?
In general you will be storing the corpus embeddings “locally” (having seeded your db previously) and should only need to retrieve the query embedding once for each search.
No, the cost for embedding is only charged once.
The corresponding code simply saves the embedding vector data locally and reloads it.
# save vector db
vector_db.save_local(store_path)
# load vector db
vector_db=FAISS.load_local(store_path, OpenAIEmbeddings(model="text-embedding-3-small"))
The only place where vector data is being created using embeddings is as follows.
# create vector db
vector_db=FAISS.from_texts(chunks, embedding=embedding)