Find answers from the community

Updated 3 months ago

Embeddings

I had a quick question about how it would be possible to access the embeddings inside an index for comparison? I have tried printing output.source_nodes[0].node.embedding but it returns none rather than the actual embedding
L
a
5 comments
Hmm, not really an easy way to return the embeddings at the moment

One option is (if you aren't using a 3td party vectordb integration), is to fetch nodes from the vector store using the node ID from the source nodes

index.vector_store._data.embedding_dict[node_id]
ah okay im using faiss index so i will look into it but thank you!
Sorry I looked into the faiss index and there is nothing on the documentation about retrieving specific embeddings do you think the best way would to be retrieve the source and re embed it?
Might be the best way! Embeddings are cheap thankfully lol

Just use this code to get the proper text for embeddings

Plain Text
from llama_index.schema   import MetadataMode

text = response.source_nodes[0].node.get_content(metadata_mode=MetataDataMode.EMBED)

embedding = embed_model.get_text_embedding(text)


You can get the embed model from the service context as well
service_context.embed_model
I will try this thank you so much!
Add a reply
Sign up and join the conversation on Discord