Replies: 4 comments
-
🤖 Hi there, To add more documents to an existing # Assuming `index_doc_summary` is an instance of IndexDocumentSummary
# `summary_node` is a new BaseNode instance representing the summary
# and `new_nodes` is a list of new BaseNode instances you want to add
index_doc_summary.add_summary_and_nodes(summary_node, new_nodes) Please note that the The
You can find more details in the source code of the I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Can you tell me the difference between the DocumentSummaryIndex and IndexDocumentSummary class please? What I get is a DocumentSummaryIndex class, how can I add nodes to it using the IndexDocumentSummary class? |
Beta Was this translation helpful? Give feedback.
-
Lets say that I have an index named "doc_summary_index" which I loaded from a file and is of the type DocumentSummaryIndex class. How can I add new summaries to it. The solution you provided earlier uses the IndexDocumentSummary class. How are they related. Can you please write the code I would need to add a new summary and all the nodes to a DocumentSummaryIndex class. Also, how do I generate new summaries from Documents without creating a new index. storage_context = StorageContext.from_defaults(persist_dir="doc_summary_index") |
Beta Was this translation helpful? Give feedback.
-
🤖 Hello, The To add a new summary and all the nodes to a def _add_nodes_to_index(
self,
index_struct: IndexDocumentSummary,
nodes: Sequence[BaseNode],
show_progress: bool = False,
) -> None:
"""Add nodes to index."""
doc_id_to_nodes = defaultdict(list)
for node in nodes:
if node.ref_doc_id is None:
raise ValueError(
"ref_doc_id of node cannot be None when building a document "
"summary index"
)
doc_id_to_nodes[node.ref_doc_id].append(node)
summary_node_dict = {}
items = doc_id_to_nodes.items()
iterable_with_progress = get_tqdm_iterable(
items, show_progress, "Summarizing documents"
)
for doc_id, nodes in iterable_with_progress:
nodes_with_scores = [NodeWithScore(node=n) for n in nodes]
# get the summary for each doc_id
summary_response = self._response_synthesizer.synthesize(
query=self._summary_query,
nodes=nodes_with_scores,
)
summary_response = cast(Response, summary_response)
summary_node_dict[doc_id] = TextNode(
text=summary_response.response,
relationships={
NodeRelationship.SOURCE: RelatedNodeInfo(node_id=doc_id)
},
)
self.docstore.add_documents([summary_node_dict[doc_id]])
logger.info(
f"> Generated summary for doc {doc_id}: " f"{summary_response.response}"
)
for doc_id, nodes in doc_id_to_nodes.items():
index_struct.add_summary_and_nodes(summary_node_dict[doc_id], nodes) To generate new summaries from Documents without creating a new index using the summary_response = self._response_synthesizer.synthesize(
query=self._summary_query,
nodes=nodes_with_scores,
)
summary_response = cast(Response, summary_response) I hope this helps! Let me know if you have any other questions. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Question Validation
Question
[Question]: Hi, I am using the DocumentSummaryIndex functionality. Once I create a DocumentSummaryIndex, how can I add more documents to it? It says that I can add nodes using the _insert, or _add_nodes_to_index function. I tried using that but it doesn;t seem to work as it doesn't insert the text of each node. It just inserts the summary and the list of questions as 1 node. Can you please give me an example of how to 1. get a new summary for a document without creating a new DocumentSummaryIndex and 2. How to add that summary and all the corresponding nodes to an existing Index. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions