A Python application that demonstrates the use of vector databases for efficient document search and retrieval using LangChain and Pinecone. This implementation showcases a Retrieval-Augmented Generation (RAG) system that enhances Large Language Model responses with relevant context from your documents.
This project implements a document ingestion and search system that:
- Loads text documents using LangChain's document loaders
- Splits them into manageable chunks using character-based text splitting
- Creates vector embeddings using OpenAI's embedding model
- Stores these embeddings in Pinecone for efficient similarity search
- Provides a RAG implementation for context-aware question answering
- Document ingestion pipeline with customizable chunk sizes
- Vector embeddings generation using OpenAI
- Efficient similarity search using Pinecone vector database
- Context-aware question answering using LangChain's retrieval chain
- Customizable prompt templates for different use cases
- Python 3.x
- Pipenv for dependency management
- OpenAI API key
- Pinecone API key and environment
Create a .env file with the following variables:
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_ENVIRONMENT=your_pinecone_environment
INDEX_NAME=your_pinecone_index_name
- Clone the repository
- Install dependencies using Pipenv:
pipenv install
- Create and configure your
.envfile with the required API keys
Run the ingestion script to process and store documents:
python ingestion.pyThis will:
- Load the text document
- Split it into chunks of 1000 characters
- Create embeddings
- Store them in Pinecone
Run the main script to perform context-aware question answering:
python main.pyThe system will:
- Retrieve relevant document chunks from Pinecone
- Use LangChain's retrieval chain to generate context-aware responses
- Provide answers based on the retrieved context
- Uses
CharacterTextSplitterwith 1000-character chunks for document processing - Implements OpenAI embeddings for vector representation
- Utilizes LangChain's hub prompts for retrieval QA
- Employs the "stuff" documents chain for combining retrieved documents
- Implements a retrieval chain for context-aware responses
ingestion.py: Handles document processing and storagemain.py: Implements the RAG system for question answeringmain-custom-prompt.py: Alternative implementation with custom prompts
Contributions are welcome! Please feel free to submit a Pull Request.