localhost

Learn how to set up the NodeRAG API client and generate answers from requests

Set Up API Client

Make sure you have already indexed your corpus, then start the API server with the following command:

python -m NodeRAG.search -f path/to/main_folder

This will launch a Flask-based API client.

client

You can modify the localhost address and port by updating config.url and config.port in your configuration file.

#==============================================================================
# Document Processing Configuration
#==============================================================================
config:
  # Search Server Settings
  url: '127.0.0.1'                  # Server URL for search service
  port: 5000                        # Server port number

Use in Terminal

After setting up the client, you can use NodeRAG directly from the command line. The request code is fully encapsulated for ease of use.

Basic Query

python -m NodeRAG -f path/to/main_folder -q "your question"

Return Answer with Retrieval Context

To retrieve related context, use the -r flag:

python -m NodeRAG -f path/to/main_folder -q "your question" -r

To retrieve both the answer and its associated context, use the -r -a flag:

python -m NodeRAG -f path/to/main_folder -q "your question" -r -a

teminal_answer

Use in Python / Jupyter Notebook (Common way)

You can interact with the NodeRAG API using Python or within a Jupyter Notebook via HTTP requests. Below is a common usage example.

import requests

# Configure API endpoint
url = '127.0.0.1'
port = 5000
localhost = f'http://{url}:{port}'
question = 'who is harry potter?'
data = {'question': question}

# Request answer only
response = requests.post(localhost + '/answer', json=data)
print(response.json()['answer'])

# Request retrieval context only
response = requests.post(localhost + '/retrieval', json=data)
print(response.json()['retrieval'])

# Request both answer and retrieval context
response = requests.post(localhost + '/answer_retrieval', json=data)
result = response.json()
print({'answer': result['answer'], 'retrieval': result['retrieval']})

Explanation

  • POST /answer: Returns the generated answer to your query.
  • POST /retrieval: Returns the relevant context retrieved from the corpus.
  • POST /answer_retrieval: Returns both the answer and its associated context.

⚙️ Note: Ensure the API server is running before sending requests. You can configure the host and port in Node_config.yaml via config.url and config.port.

client_result


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