RAG implementation for gptme context management
Project description
gptme-rag
A powerful RAG (Retrieval-Augmented Generation) system that enhances AI interactions by providing relevant context from your local files. Built primarily for gptme, but can be used standalone.
RAG systems improve AI responses by retrieving and incorporating relevant information from a knowledge base into the generation process. This leads to more accurate, contextual, and factual responses.
Features
- ๐ Document indexing with ChromaDB
- Fast and efficient vector storage
- Semantic search capabilities
- Persistent storage
- ๐ Semantic search with embeddings
- Relevance scoring
- Token-aware context assembly
- Clean output formatting
- ๐ Smart document processing
- Streaming large file handling
- Automatic document chunking
- Configurable chunk size/overlap
- Document reconstruction
- ๐ File watching and auto-indexing
- Real-time index updates
- Pattern-based file filtering
- Efficient batch processing
- Automatic persistence
- ๐ ๏ธ CLI interface for testing and development
- Index management
- Search functionality
- Context assembly
- File watching
Quick Start
# Install (requires Python 3.10+)
pipx install gptme-rag # or: pip install gptme-rag
# Index your documents
gptme-rag index ./docs --pattern "**/*.md"
# Search
gptme-rag search "What is the architecture of the system?"
For development installation:
git clone https://github.com/ErikBjare/gptme-rag.git
cd gptme-rag
poetry install
Usage
Indexing Documents
# Index markdown files in a directory
gptme-rag index /path/to/documents --pattern "**/*.md"
# Index with custom persist directory
gptme-rag index /path/to/documents --persist-dir ./index
Searching
# Basic search
gptme-rag search "your query here"
# Advanced search with options
gptme-rag search "your query" \
--n-results 5 \
--persist-dir ./index \
--max-tokens 4000 \
--show-context
File Watching
The watch command monitors directories for changes and automatically updates the index:
# Watch a directory with default settings
gptme-rag watch /path/to/documents
# Watch with custom pattern and ignore rules
gptme-rag watch /path/to/documents \
--pattern "**/*.{md,py}" \
--ignore-patterns "*.tmp" "*.log" \
--persist-dir ./index
Features:
- ๐ Real-time index updates
- ๐ฏ Pattern matching for file types
- ๐ซ Configurable ignore patterns
- ๐ Efficient batch processing
- ๐พ Automatic persistence
The watcher will:
- Perform initial indexing of existing files
- Monitor for file changes (create/modify/delete/move)
- Update the index automatically
- Handle rapid changes efficiently with debouncing
- Continue running until interrupted (Ctrl+C)
Performance Benchmarking
The benchmark commands help measure and optimize performance:
# Benchmark document indexing
gptme-rag benchmark indexing /path/to/documents \
--pattern "**/*.md" \
--persist-dir ./benchmark_index
# Benchmark search performance
gptme-rag benchmark search /path/to/documents \
--queries "python" "documentation" "example" \
--n-results 10
# Benchmark file watching
gptme-rag benchmark watch-perf /path/to/documents \
--duration 10 \
--updates-per-second 5
Features:
- ๐ Comprehensive metrics
- Operation duration
- Memory usage
- Throughput
- Custom metrics per operation
- ๐ฌ Multiple benchmark types
- Document indexing
- Search operations
- File watching
- ๐ Performance tracking
- Memory efficiency
- Processing speed
- System resource usage
Example benchmark output:
โโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโ
โ Operation โ Duration(s) โ Memory(MB) โ Throughput โ Additional Metrics โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ indexing โ 0.523 โ 15.42 โ 19.12/s โ files: 10 โ
โ search โ 0.128 โ 5.67 โ 23.44/s โ queries: 3 โ
โ file_watching โ 5.012 โ 8.91 โ 4.99/s โ updates: 25 โ
โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโ
Document Chunking
The indexer supports automatic document chunking for efficient processing of large files:
# Index with custom chunk settings
gptme-rag index /path/to/documents \
--chunk-size 1000 \
--chunk-overlap 200
# Search with chunk grouping
gptme-rag search "your query" \
--group-chunks \
--n-results 5
Features:
- ๐ Streaming processing
- Handles large files efficiently
- Minimal memory usage
- Progress reporting
- ๐ Smart chunking
- Configurable chunk size
- Overlapping chunks for context
- Token-aware splitting
- ๐ Enhanced search
- Chunk-aware relevance
- Result grouping by document
- Full document reconstruction
Example Output:
Most Relevant Documents:
1. documentation.md#chunk2 (relevance: 0.85)
Detailed section about configuration options, including chunk size and overlap settings.
[Part of: documentation.md]
2. guide.md#chunk5 (relevance: 0.78)
Example usage showing how to process large documents efficiently.
[Part of: guide.md]
3. README.md#chunk1 (relevance: 0.72)
Overview of the chunking system and its benefits for large document processing.
[Part of: README.md]
Full Context:
Total tokens: 850
Documents included: 3 (from 3 source documents)
Truncated: False
The chunking system automatically:
- Splits large documents into manageable pieces
- Maintains context across chunk boundaries
- Groups related chunks in search results
- Provides document reconstruction when needed
Development
Running Tests
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=gptme_rag
Project Structure
gptme_rag/
โโโ __init__.py
โโโ cli.py # CLI interface
โโโ indexing/ # Document indexing
โ โโโ document.py # Document model
โ โโโ indexer.py # ChromaDB integration
โโโ query/ # Search functionality
โ โโโ context_assembler.py # Context assembly
โโโ utils/ # Utility functions
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run tests and linting
- Submit a pull request
Releases
Releases are automated through GitHub Actions. The process is:
- Update version in pyproject.toml
- Commit the change:
git commit -am "chore: bump version to x.y.z" - Create and push a tag:
git tag vx.y.z && git push origin master vx.y.z - Create a GitHub release (can be done with
gh release create vx.y.z) - The publish workflow will automatically:
- Run tests
- Build the package
- Publish to PyPI
Integration with gptme
This package is designed to integrate with gptme to provide AI assistants with relevant context from your local files. When used with gptme, it:
- Automatically indexes your project files
- Enhances AI responses with relevant context
- Provides semantic search across your codebase
- Maintains a persistent knowledge base
- Assembles context intelligently within token limits
To use with gptme, simply install both packages and gptme will automatically detect and use gptme-rag for context management.
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gptme_rag-0.5.1.tar.gz.
File metadata
- Download URL: gptme_rag-0.5.1.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d679a3afe5af3de8978923b9b2b83ef5bdf70d4d4d22fd33d99c782ac6b7b302
|
|
| MD5 |
d0478a1702ac354b8a06bc525759924f
|
|
| BLAKE2b-256 |
421929cab114cf18cda357c650f2257e3d04fb3fc638060b125d0ac69cd319bd
|
File details
Details for the file gptme_rag-0.5.1-py3-none-any.whl.
File metadata
- Download URL: gptme_rag-0.5.1-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
620c878dcf1b62f0936c00179c889331e29a81af5c0319b92bac7ecc56cc8d3f
|
|
| MD5 |
7d3cc7591a507e23420d15c5644ce8e6
|
|
| BLAKE2b-256 |
2b2b2c741349b89acd4e8d4f967061fafe9705593285ca139feeb0ec9fb257cb
|