Bring your own embeddings with InMemoryDocumentStore() #4663
-
Is it possible to use pre-computed embeddings when using the I see it is possible with FAISS #1085 but I do not want to use FAISS or the other document store modules because of added dependencies. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hello @davidgibsonp! When you call An example: from haystack import Document
from haystack.document_stores import InMemoryDocumentStore
from haystack.nodes import EmbeddingRetriever
# embeddings generation (you should skip this part)
texts=["Test document 1", "Test document 2", "Test document 3"]
docs = [Document(text) for text in texts]
document_store = InMemoryDocumentStore()
document_store.write_documents(docs)
retriever = EmbeddingRetriever(
document_store=document_store,
embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
)
document_store.update_embeddings(retriever)
# you can start from here
docs_w_embeddings = document_store.get_all_documents(return_embedding=True)
new_document_store = InMemoryDocumentStore()
new_document_store.write_documents(docs_w_embeddings) Now, if you type Don't hesitate to ask for any clarification. |
Beta Was this translation helpful? Give feedback.
-
Hi |
Beta Was this translation helpful? Give feedback.
Thanks for the response! This does work, but as a clarification, I already computed the embeddings elsewhere and they are stored in a table. I do not want to compute the embeddings using the Haystack retriever. Just select the
content
andembedding
and add them to theInMemoryDocumentStore
.But your example did get me on the right path! Does this design pattern make sense?