Find answers from the community

s
F
Y
a
P
Updated last month

Hi all

Hi all,
I want to add summary of each node to it's metadata and embed them altogether. How do I do it?
I'm doing this to improve the retrieval accuracy, Is this the right approach?
L
1 comment
You can generate a summary of a document using a temporary list index, then add it to metadata, but only for embeddings.

Plain Text
for document in documents
  temp_index = ListIndex.from_documents([document])
  summary = temp_index.as_query_engine().query("Summarize: ")
  document.metadata["summary"] = summary
  document.excluded_llm_metadata_keys = ["summary"]

index = VectorStoreIndex.from_documents(documents)


If you would rather do this with nodes, the same logic applies. Just change the index creation to index = VectorStoreIndex(nodes) and similar for the list index
Add a reply
Sign up and join the conversation on Discord