A Retrieval Augmented Generation (RAG) application built with Streamlit, LangChain, and NVIDIA's NIM (NVIDIA Inference Microservices) API. This application allows you to query documents using natural language and get AI-powered responses based on the document content.
- Document Processing: Automatically loads and processes PDF documents from a specified directory
- Vector Embeddings: Creates vector embeddings using NVIDIA's embedding models
- Semantic Search: Performs similarity search on document chunks using FAISS vector store
- AI-Powered Responses: Uses NVIDIA's Llama 3.1 Nemotron model for generating contextual answers
- Interactive UI: Clean Streamlit interface for easy interaction
- Document Context: Shows relevant document chunks used for generating responses
- Python 3.8 or higher
- NVIDIA API Key (sign up at NVIDIA NGC)
- PDF documents to query (place in
./us_censusdirectory)
-
Clone the repository (or download the script):
git clone https://github.com/CyprianFusi/nvidia-nim-rag.git cd nvidia-nim-rag -
Install required packages:
pip install -r requirements.txt
-
Set up environment variables (optional): Create a
.envfile in the project root:NVIDIA_API_KEY=your_nvidia_api_key_here -
Prepare your documents:
- Create a directory named
us_censusin the project root - Place your PDF documents in this directory
- Create a directory named
-
Start the application:
streamlit run rag_app_nvidia.py
-
Enter your NVIDIA API Key:
- In the sidebar, enter your NVIDIA API Key
- If you haven't set it in the
.envfile, you'll need to enter it manually
-
Embed your documents:
- Click the "Embed Documents" button in the sidebar
- Wait for the processing to complete (you'll see "Vector Store DB Is Ready")
-
Ask questions:
- Type your question in the text input field
- The AI will provide answers based on your document content
- View the relevant document chunks in the expandable "Document Similarity Search" section
- LLM Model:
nvidia/llama-3.1-nemotron-nano-vl-8b-v1 - Chunk Size: 700 characters
- Chunk Overlap: 50 characters
- Document Limit: First 30 documents (configurable)
You can modify these parameters in the code:
# Text splitting parameters
chunk_size=700 # Size of each text chunk
chunk_overlap=50 # Overlap between chunks
# Document processing
st.session_state.docs[:30] # Number of documents to process
# Model selection
model="nvidia/llama-3.1-nemotron-nano-vl-8b-v1" # NVIDIA model to useproject-root/
│
├── rag_app_nvidia.py # Main application file
├── .env # Environment variables (optional)
├── us_census/ # Directory containing PDF documents
│ ├── document1.pdf
│ ├── document2.pdf
│ └── ...
└── README.md # This file
- Document Loading: The application loads PDF files from the
us_censusdirectory - Text Splitting: Documents are split into manageable chunks for processing
- Vector Embedding: Text chunks are converted to vector embeddings using NVIDIA's embedding model
- Vector Store: Embeddings are stored in a FAISS vector database for efficient similarity search
- Query Processing: User questions are converted to embeddings and matched against document chunks
- Response Generation: Relevant chunks are sent to the NVIDIA LLM along with the user question to generate contextual answers
This application uses the following NVIDIA NIM services:
- Embeddings: NVIDIA embeddings model for text vectorization
- LLM: Llama 3.1 Nemotron model for text generation
- Initial document embedding may take some time depending on document size and quantity
- Response times are logged in the console for performance monitoring
- Vector store is cached in Streamlit session state for efficiency
- API Key Error: Ensure your NVIDIA API key is valid and has access to NIM services
- No Documents Found: Check that PDF files are placed in the
us_censusdirectory - Memory Issues: Reduce the number of documents processed or chunk size if experiencing memory problems
- Slow Performance: Consider reducing chunk size or number of documents for faster processing
- "Please enter your NVIDIA API Key to proceed further" - Add your API key in the sidebar
- Processing errors - Check document format and ensure PDFs are readable
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
This project is open source and available under the MIT License.
- Built with LangChain framework
- Powered by NVIDIA NIM APIs
- UI created with Streamlit




