import module
Learn how to import modules to use NodeRAG directly in your code.
less than a minute
Import Modules
Build a search engine quickly with minimal setup:
from NodeRAG import NodeConfig, NodeSearch
# Load configuration from the main folder
config = NodeConfig.from_main_folder(r"C:\Users\Terry_Xu\Desktop\HP")
# Initialize search engine
search = NodeSearch(config)
Answer a Question
# Query the system
ans = search.answer('who is harry potter?')
# 'ans' is an object with several accessible attributes:
# Response: the generated answer to your question
print(ans.response)
# Number of tokens in the answer
print(ans.response_tokens)
# Retrieval info: the context used to generate the answer
print(ans.retrieval_info)
# Number of tokens in the retrieval context
print(ans.retrieval_tokens)
Notes
search.answer()
returns an object that encapsulates both the answer and the retrieval context, along with useful metadata.- This method is ideal for quick integration into Python scripts or Jupyter notebooks, without setting up an API server.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.