Find answers from the community

Updated last year

Hello,

Hello,

Quick question: How can I retrieve nodes from the vector index? I am using MongoDB Reader.
b
T
W
19 comments
you want to retrieve the nodes that it is using to send to llm?
this will get you the text of each source_nodes sources = [s.node.get_text() for s in response.source_nodes]
if you dont' want it to send to the llm you can do response_mode=no_text
Plain Text
no_text: Only runs the retriever to fetch the nodes that would have been sent to the LLM, without actually sending them. Then can be inspected by checking response.source_nodes.
Sorry, still new at this and got a little confused. So now I am using load_index_from_storage to load indices, and to get their nodes I shall use what you've shared?

Want to use the retrived nodes from the indices to create a new VectorStoreIndex.
want to paste some code?
basically the idea is if you do .as_chat_engine or .as_query_engine and then do result = query_engine.query("prompt") you can do result.source_nodes
def initialize_combined_data(self, user_id):
try:
# Fetch the individual indices from MongoDB
user_document = user_collection.find_one({'user_id': user_id})
if not user_document or 'notion_index_id' not in user_document or 'confluence_index_id' not in user_document:
raise ValueError("Settings for Notion or Confluence have not been configured for this user.")

# Re-create the storage context with the MongoDB document store and index store
storage_context_combined = StorageContext.from_defaults(
docstore=MongoDocumentStore.from_uri(uri=mongo_uri),
index_store=MongoIndexStore.from_uri(uri=mongo_uri),
)

# Load the Notion and Confluence project indices from storage using the identifiers
notion_project_index = load_index_from_storage(
storage_context=storage_context_combined,
index_id=user_document['notion_index_id']
)

confluence_space_index = load_index_from_storage(
storage_context=storage_context_combined,
index_id=user_document['confluence_index_id']
)

# Fetch the combined nodes from MongoDB or create by combining Notion and Confluence nodes
notion_nodes = notion_project_index.retrieve_all_documents()
confluence_nodes = confluence_space_index.retrieve_all_documents()

combined_nodes = notion_nodes + confluence_nodes

# Add combined nodes to the document store
storage_context_combined.docstore.add_documents(combined_nodes)

# Create a new combined index from the combined nodes
combined_index = VectorStoreIndex(combined_nodes, storage_context=storage_context_combined, service_context=service_context)
combined_index_id = combined_index.index_id
yeah idk whats going on here πŸ˜‚
it doesn't loook like you're querying the index at all
Yeah, I have a separate function for using it in a chat engine
Just need to get nodes of two indices together to create a new one.
Guess I could just save the nodes themselves in MongoDB as separate, but that would be too much data for it I think (I think...)
You can get nodes from Index like this:
Plain Text
nodes_mongo = index_1.docstore.docs
nodes_notion = index_2.docstore.docs
@WhiteFang_Jr Thanks! Do we have documentation for this kind of case?
Add a reply
Sign up and join the conversation on Discord