Find answers from the community

Updated 3 months ago

Embeddings

Hi, how can I create a Property Graph with embeddings directly? If I use the simple recipe here: https://github.com/run-llama/llama_index/blob/main/docs/docs/module_guides/indexing/lpg_index_guide.md?plain=1#L430 I get entities with no embeddings. I tried looking at the code for _insert_nodes in https://github.com/run-llama/llama_index/blob/main/llama-index-core/llama_index/core/indices/property_graph/base.py#L191, and I suppose I could attempt to repliace the embdding section but I was wondering whether there was an expected way to ingest a knowledge graph and have embeddings.
L
n
29 comments
Are you using neo4j? Or do the embeddings need to go into a separate vector store? (My answer will change depending on the case(
I've been using neo4j, but I am also willing to try another setup.
To keep it simple for now then, you can just set the embddding field of the Entity nodes to contain your embedding vector
You can generate embeddings using

embeddings = embed_model.get_text_embddding_batch(["text1", "text2", ...])
And then attach them to the corresponding entity
what if i have texts on the relationships, instead of the entities?
instead of -> in addition to
Sorry, I don't quite follow, do you have an example?
so my relationships have a sentences property that is a list of sentences extracted from the literature that supports this relationship.
and the relationships also have the references to the literature.
so it seems useful to index these sentences?
but maybe i'll do this in a follow up step
thanks for all your replies!
I think what I would do is insert the entire chunk of sentences, and then add a relation from those sentences

You can insert TextNodes directly with graph_store.upsert_llama_nodes(text_nodes)
Optionally, you can use those sentences when creating those embeddings for your entity nodes
thanks for the hint, I'll try that.
one question about embeddings:
the EntityNode has an embedding field
but get_text_embedding_batch returns a list of embeddings
and this is what i have
so how do i convert from a list of embeddings to an embedding?
It returns in the same order you gave the text

So maybe you have something like

Plain Text
embeddings = embed_model.get_text_embedding_batch(["entity1", "entity2", ...])

for entity, embedding in zip(entities, embeddings):
  entity.embedding = embedding
is there a way to associate more than one embedding with an entity? for now, i get the text embedding from the entity's name, but i also have a list of synonyms.
You could embed all the synoyms in a single entity node
Or embed them seperately and put relations between them, but that seems less effecient
so i would do get_text_embedding("syn1; syn2; syn3") ?
thanks πŸ™‚
Add a reply
Sign up and join the conversation on Discord