import module

Learn how to import modules to use NodeRAG directly in your code.

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.

import_module


Last modified April 5, 2025: update reproduce (f23a25c)