Skip to main content

No project description provided

Project description

NVIDIA Context Aware RAG

image

Context Aware RAG is a flexible library designed to seamlessly integrate into existing data processing workflows to build customized data ingestion and retrieval (RAG) pipelines.

Key Features

With Context Aware RAG, you can quickly build RAG pipelines to support your existing workflows.

Links

Getting Started

Prerequisites

Before you begin using Context Aware RAG, ensure that you have the following software installed.

Installation

Clone the repository

git clone git@github.com:NVIDIA/context-aware-rag.git
cd context-aware-rag/

Create a virtual environment using uv

uv venv --seed .venv
source .venv/bin/activate

Installing from source

uv pip install -e .

Optional: Building and Installing the wheel file

uv build
uv pip install vss_ctx_rag-0.5.0-py3-none-any.whl

Service Example

Setting up environment variables

Create a .env file in the root directory and set the following variables:

   NVIDIA_API_KEY=<IF USING NVIDIA>
   NVIDIA_VISIBLE_DEVICES=<GPU ID>

   OPENAI_API_KEY=<IF USING OPENAI>

   VSS_CTX_PORT_RET=<DATA RETRIEVAL PORT>
   VSS_CTX_PORT_IN=<DATA INGESTION PORT>

Build docker

make -C docker build

Using docker compose

make -C docker start_compose

This will start the following services:

  • ctx-rag-data-ingestion

    • Service available at http://<HOST>:<VSS_CTX_PORT_IN>
  • ctx-rag-data-retrieval

    • Service available at http://<HOST>:<VSS_CTX_PORT_RET>
  • neo4j

    • UI available at http://<HOST>:7474
  • milvus

  • otel-collector

  • jaeger

    • UI available at http://<HOST>:16686
  • prometheus

    • UI available at http://<HOST>:9090
  • cassandra

To change the storage volumes, export DOCKER_VOLUME_DIRECTORY to the desired directory.

Data Ingestion Example

import requests
import json

base_url = "http://<HOST>:<VSS_CTX_PORT_IN>"

headers = {"Content-Type": "application/json"}

### Initialize the service with a unique uuid
init_data = {"uuid": "1"}
### Optional: Initialize the service with a config file or context config
"""
init_data = {"config_path": "/app/config/config.yaml", "uuid": "1"}
init_data = {"context_config": yaml.safe_load(open("/app/config/config.yaml")), "uuid": "1"}
"""
response = requests.post(
    f"{base_url}/init", headers=headers, data=json.dumps(init_data)
)

# POST request to /add_doc to add documents to the service
add_doc_data_list = [
    {"document": "User1: I went hiking to Mission Peak", "doc_index": 4},
    {
        "document": "User1: Hi how are you?",
        "doc_index": 0,
        "doc_metadata": {"is_first": True},
    },
    {"document": "User1: I went hiking to Mission Peak", "doc_index": 4},
    {"document": "User1: I am great too. Thanks for asking", "doc_index": 2},
    {"document": "User2: I am good. How are you?", "doc_index": 1},
    {"document": "User2: So what did you do over the weekend?", "doc_index": 3},
    {
        "document": "User3: Guys there is a fire. Let us get out of here",
        "doc_index": 5,
        "doc_metadata": {"is_last": True},
    },
]

# Send POST requests for each document
for add_doc_data in add_doc_data_list:
    response = requests.post(
        f"{base_url}/add_doc", headers=headers, data=json.dumps(add_doc_data)
    )

Data Retrieval Example

import requests
import json


base_url = "http://<HOST>:<VSS_CTX_PORT_RET>"

headers = {"Content-Type": "application/json"}

### Initialize the service with the same uuid as the data ingestion service
init_data = {"config_path": "/app/config/config.yaml", "uuid": "1"}
response = requests.post(
    f"{base_url}/init", headers=headers, data=json.dumps(init_data)
)

### Send a retrieval request to the service
call_data = {"chat": {"question": "What happens in this situation?"}}

request_data = {"state": call_data}

response = requests.post(
    f"{base_url}/call", headers=headers, data=json.dumps(request_data)
)
print(response.json()["result"])

Acknowledgements

We would like to thank the following projects that made Context Aware RAG possible:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vss_ctx_rag-0.5.0-py3-none-any.whl (192.5 kB view details)

Uploaded Python 3

File details

Details for the file vss_ctx_rag-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: vss_ctx_rag-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 192.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.18

File hashes

Hashes for vss_ctx_rag-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 305ede6bdb99895a4ee799e41432bd42b2d0544a4739d59570133cc2e1d17b98
MD5 77c9aa72b669b2ef27bcee936927dab7
BLAKE2b-256 be9342b0eecf377f69640d11f107aa6b91bf0acf5bdbb4b8cae5c8174a29c651

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page