A flexible Retrieval-Augmented Generation (RAG) chat system that supports multiple document retrieval sources (Vectorize, Pinecone, or none) combined with OpenAI's GPT-4o-mini for intelligent answer generation.
- Multiple RAG Sources: Choose between Vectorize, Pinecone, or no external knowledge base
- Interactive CLI: Beautiful command-line interface with loading animations and colored output
- Context-Aware Responses: Generates answers based on retrieved documents and conversation context
- Extensible Architecture: Easy to add new RAG sources by implementing the base interface
- Environment-Aware: Automatically checks for required environment variables based on selected source
- Install dependencies:
uv sync
-
Set up environment variables (see Configuration section below)
-
Run the application:
uv run main.py
Edit main.py
and modify the RAG_SOURCE
variable:
from rag_source_base import RAGSourceType
# Choose one of:
RAG_SOURCE = RAGSourceType.NONE # No document retrieval (OpenAI only)
RAG_SOURCE = RAGSourceType.VECTORIZE # Use Vectorize.io for retrieval
RAG_SOURCE = RAGSourceType.PINECONE # Use Pinecone (mock implementation)
Create a .env
file in the project root with the required variables:
OPENAI_API_KEY=your-openai-api-key-here
OPENAI_API_KEY=your-openai-api-key-here
VECTORIZE_PIPELINE_ACCESS_TOKEN=your-vectorize-token
VECTORIZE_ORGANIZATION_ID=your-organization-id
VECTORIZE_PIPELINE_ID=your-pipeline-id
OPENAI_API_KEY=your-openai-api-key-here
PINECONE_API_KEY=your-pinecone-api-key
PINECONE_ENVIRONMENT=your-pinecone-environment
PINECONE_INDEX_NAME=your-pinecone-index-name
OPENAI_API_KEY=your-openai-api-key-here
- Go to OpenAI API
- Create a new API key
- Add billing information to your OpenAI account
- Sign up at Vectorize.io
- Create a pipeline for your documents
- Get your organization ID, pipeline ID, and access token from the dashboard
- Sign up at Pinecone
- Create a new index
- Get your API key and environment from the dashboard
- Note: Currently using mock implementation - replace with actual Pinecone client
rag-python/
├── main.py # Main application entry point
├── rag_chat.py # Core RAG chat logic
├── rag_source_base.py # Base interface for RAG sources
├── vectorize_wrapper.py # Vectorize.io implementation
├── pinecone_wrapper.py # Pinecone mock implementation
├── cli_interface.py # Command-line interface and styling
├── example_usage.py # Programmatic usage examples
├── pyproject.toml # Project dependencies
├── uv.lock # Dependency lock file
└── .env # Environment variables (create this)
Run the main application:
python main.py
The application will:
- Check your environment variables
- Initialize the selected RAG source
- Start an interactive chat session
- Display retrieved documents (if using external source)
- Generate and show AI responses
from rag_chat import RAGChat
from cli_interface import CLIInterface
from vectorize_wrapper import VectorizeWrapper
# With Vectorize
cli = CLIInterface("My RAG App")
vectorize_source = VectorizeWrapper()
rag = RAGChat(cli, rag_source=vectorize_source)
answer = rag.chat("What is machine learning?")
print(answer)
# Without external source
rag_no_source = RAGChat(cli, rag_source=None)
answer = rag_no_source.chat("What is machine learning?")
print(answer)
- User asks a question
- System queries the RAG source for relevant documents
- Retrieved documents are formatted as context
- Context + question sent to OpenAI GPT-4o-mini
- AI generates answer based on provided context
- Answer displayed with source information
- User asks a question
- Question sent directly to OpenAI GPT-4o-mini
- AI generates answer from general knowledge
- Answer displayed
To add a new RAG source (e.g., Chroma, Weaviate):
- Create a wrapper class:
from rag_source_base import RAGSourceBase
class MyNewWrapper(RAGSourceBase):
def retrieve_documents(self, question: str, num_results: int = 5):
# Implement your retrieval logic
return documents
def get_required_env_vars(self):
return ["MY_API_KEY", "MY_INDEX_NAME"]
- Add to enum in
rag_source_base.py
:
class RAGSourceType(Enum):
NONE = "none"
VECTORIZE = "vectorize"
PINECONE = "pinecone"
MY_NEW_SOURCE = "my_new_source" # Add this
- Update
get_rag_source()
inmain.py
:
elif RAG_SOURCE == RAGSourceType.MY_NEW_SOURCE:
wrapper = MyNewWrapper()
return wrapper, wrapper.get_required_env_vars()
Missing environment variables:
- Check your
.env
file exists and has the correct variables - Ensure no extra spaces around the
=
in your.env
file
API key errors:
- Verify your OpenAI API key is valid and has billing enabled
- Check Vectorize/Pinecone credentials are correct
Import errors:
- Run
uv sync
to install all dependencies - Ensure you're using Python 3.8+
No documents found:
- Verify your Vectorize pipeline has documents indexed
- Check your Pinecone index has embeddings
- Check the application logs for specific error messages
- Verify all environment variables are set correctly
- Test with
RAG_SOURCE = RAGSourceType.NONE
to isolate issues - Ensure your API keys have the necessary permissions
python >= 3.8
litellm
- Multi-provider LLM interfacevectorize-client
- Vectorize.io Python clientpython-dotenv
- Environment variable management
See pyproject.toml
for complete dependency list.