Load pre-computed embedding into document store object
Question I may miss something here. Is there a way to directly load pre-computed embedding(e.g. DPR on Wikipedia dump) into the document store object? I see FAISSDocumentStore has two components, documents, and their embeddings. It seems that all tutorials first write the document with write_documents(dicts), and then call update_embeddings(retriever). But if I already have the pre-computed embedding in a pickle file for each document, how can I load the document and embedding together. Thank you for this amazing framework.
Hey @jqJordan ,
Yep, that's absolutely possible.
Just put your embedding in the dict as a numpy array with the key embedding. It will then be converted to Haystack's Document object where the embedding is one of the attributes: https://github.com/deepset-ai/haystack/blob/4ab1bc3c3ec0f7f2bb86625e4a71b231c034f5dd/haystack/schema.py#L41
Thank you so much for the speedy response. I did a small test and it worked very well.
documents = [{"text": "abc", "meta": {"author": "a"}, 'embedding':np.array([0.1,0.2,0.3])}, {"text": "xyz", "meta": {"author": "b"}, 'embedding':np.array([1.1,1.2,1.3])}]
test = FAISSDocumentStore(vector_dim=3)
test.write_documents(documents)
test.get_all_documents(return_embedding=True)