A powerful Retrieval-Augmented Generation (RAG) system for document-based question answering.
- Multiple Document Formats: Support for PDF, DOCX, TXT, MD, and HTML files
- Intelligent Chunking: Automatic text splitting with configurable chunk sizes and overlap
- Flexible Embeddings: Use either sentence-transformers (local) or OpenAI embeddings
- Vector Storage: ChromaDB for efficient similarity search
- AI-Powered Answers: Generate contextual answers using OpenAI GPT models
- CLI Interface: Easy-to-use command-line interface
- Interactive Mode: Query your documents interactively
- Clone the repository:
git clone <repository-url>
cd boogle- Install dependencies:
pip install -r requirements.txt- Set up environment variables (optional, for OpenAI):
cp .env.example .env
# Edit .env and add your OPENAI_API_KEYIngest documents from a directory:
python main.py ingest --directory ./documentsIngest specific files:
python main.py ingest --files doc1.pdf doc2.txt doc3.mdAsk a question:
python main.py query "What is the main topic of the documents?"Interactive mode:
python main.py query --interactivepython main.py statspython main.py reset# Ingest all documents from a directory (recursive)
python main.py ingest --directory ./my_docs
# Ingest specific files
python main.py ingest --files report.pdf notes.txt
# Custom chunk settings
python main.py ingest --directory ./docs --chunk-size 500 --chunk-overlap 100
# Use OpenAI embeddings (requires API key)
python main.py ingest --directory ./docs --use-openai-embeddings# Simple query
python main.py query "What are the key findings?"
# Retrieve more context documents
python main.py query "Summarize the methodology" --top-k 10
# Use a different model
python main.py query "What is the conclusion?" --model gpt-4
# Hide sources
python main.py query "What is the main argument?" --no-sources
# Interactive mode
python main.py query --interactive# Use a custom collection name
python main.py --collection my_collection ingest --directory ./docs
# Custom persist directory
python main.py --persist-dir ./my_vector_db ingest --directory ./docsThe RAG system consists of several components:
- DocumentLoader: Loads documents from various file formats
- TextChunker: Splits documents into manageable chunks
- EmbeddingGenerator: Generates vector embeddings for text
- VectorStore: Stores and retrieves embeddings using ChromaDB
- Retriever: Finds relevant documents for a query
- Generator: Generates answers using LLM and context
- RAGPipeline: Orchestrates all components
chunk_size: Maximum size of each text chunk (default: 1000 characters)chunk_overlap: Overlap between chunks (default: 200 characters)
- Local (default):
sentence-transformers/all-MiniLM-L6-v2 - OpenAI:
text-embedding-3-small(requires API key)
- Default:
gpt-3.5-turbo - Alternative:
gpt-4,gpt-4-turbo, etc.
You can also use the RAG system programmatically:
from src.rag import RAGPipeline
# Initialize pipeline
pipeline = RAGPipeline(
collection_name="my_docs",
chunk_size=1000,
top_k=5
)
# Ingest documents
pipeline.ingest_documents(directory_path="./documents")
# Query
result = pipeline.query("What is this about?")
print(result['answer'])
print(result['sources'])
# Get stats
stats = pipeline.get_stats()
print(f"Total documents: {stats['total_documents']}")boogle/
├── src/
│ └── rag/
│ ├── __init__.py
│ ├── document_loader.py # Document loading
│ ├── text_chunker.py # Text chunking
│ ├── embeddings.py # Embedding generation
│ ├── vector_store.py # Vector database
│ ├── retriever.py # Document retrieval
│ ├── generator.py # Answer generation
│ └── rag_pipeline.py # Main pipeline
├── main.py # CLI interface
├── requirements.txt # Dependencies
├── .env.example # Environment variables template
└── README.md # This file
- Python 3.8+
- See
requirements.txtfor package dependencies
OPENAI_API_KEY: Required for OpenAI embeddings and generation
- Make sure the document directory exists and contains supported file types
- Check file permissions
- Verify your
OPENAI_API_KEYis set correctly in.env - Check your OpenAI account has sufficient credits
- Reduce
chunk_sizefor large documents - Process fewer documents at once
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.