Skip to main content

Enterprise RAG system for knowledge management

Project description

AI RAG Enterprise Knowledge Base

Python 3.11+ FastAPI LangChain License: MIT

A production-grade Retrieval-Augmented Generation (RAG) system for enterprise knowledge management. Ingest documents, build semantic indexes, and query your knowledge base using natural language.

๐Ÿš€ Features

  • Multi-format Document Ingestion: PDF, DOCX, TXT, Markdown, HTML
  • Semantic Search: ChromaDB vector store with sentence-transformers embeddings
  • LLM Integration: OpenAI GPT-4, Anthropic Claude, or local models via Ollama
  • REST API: FastAPI with OpenAPI documentation
  • Authentication: JWT-based auth with role-based access control
  • Async Processing: Background document processing with Celery
  • Observability: Structured logging, Prometheus metrics, health checks

๐Ÿ“ Project Structure

ai-rag-enterprise-knowledge-base/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ api/                 # FastAPI routes
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ documents.py     # Document upload/management
โ”‚   โ”‚   โ”œโ”€โ”€ query.py         # RAG query endpoints
โ”‚   โ”‚   โ””โ”€โ”€ auth.py          # Authentication
โ”‚   โ”œโ”€โ”€ core/                # Core RAG logic
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ embeddings.py    # Embedding models
โ”‚   โ”‚   โ”œโ”€โ”€ vectorstore.py   # ChromaDB integration
โ”‚   โ”‚   โ”œโ”€โ”€ retriever.py     # Document retrieval
โ”‚   โ”‚   โ”œโ”€โ”€ llm.py           # LLM abstraction
โ”‚   โ”‚   โ””โ”€โ”€ chains.py        # LangChain RAG chains
โ”‚   โ”œโ”€โ”€ ingestion/           # Document processing
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ loaders.py       # File loaders
โ”‚   โ”‚   โ”œโ”€โ”€ chunkers.py      # Text splitting
โ”‚   โ”‚   โ””โ”€โ”€ pipeline.py      # Ingestion pipeline
โ”‚   โ”œโ”€โ”€ models/              # Pydantic models
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ documents.py
โ”‚   โ”‚   โ””โ”€โ”€ queries.py
โ”‚   โ”œโ”€โ”€ config.py            # Configuration
โ”‚   โ””โ”€โ”€ main.py              # Application entrypoint
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ conftest.py
โ”‚   โ”œโ”€โ”€ test_api/
โ”‚   โ”œโ”€โ”€ test_core/
โ”‚   โ””โ”€โ”€ test_ingestion/
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿ› ๏ธ Installation

# Clone the repository
git clone https://github.com/Shivay00001/ai-rag-enterprise-knowledge-base.git
cd ai-rag-enterprise-knowledge-base

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set environment variables
cp .env.example .env
# Edit .env with your API keys

# Run the application
uvicorn src.main:app --reload

๐Ÿณ Docker

docker-compose up -d

๐Ÿ“– API Usage

Upload Document

curl -X POST "http://localhost:8000/api/v1/documents" \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@knowledge_base.pdf"

Query Knowledge Base

curl -X POST "http://localhost:8000/api/v1/query" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"question": "What is our refund policy?", "top_k": 5}'

โš™๏ธ Configuration

Variable Description Default
OPENAI_API_KEY OpenAI API key -
EMBEDDING_MODEL Embedding model name all-MiniLM-L6-v2
LLM_MODEL LLM model name gpt-4-turbo-preview
CHROMA_PERSIST_DIR ChromaDB storage path ./data/chroma
CHUNK_SIZE Document chunk size 1000
CHUNK_OVERLAP Chunk overlap 200

๐Ÿงช Testing

pytest tests/ -v --cov=src

๐Ÿ“„ License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_rag_enterprise_knowledge_base-1.0.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file ai_rag_enterprise_knowledge_base-1.0.0.tar.gz.

File metadata

File hashes

Hashes for ai_rag_enterprise_knowledge_base-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fafcaa5608012cc58a1f10cf2daadc54614353b799e599b173f84f290e2c8060
MD5 25ce30e057873434366c735d86ec9385
BLAKE2b-256 5f5b05e9c5026c1d3838db7d8d197a700e4a5aa1416fc09b589e94a7d8ad8239

See more details on using hashes here.

File details

Details for the file ai_rag_enterprise_knowledge_base-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_rag_enterprise_knowledge_base-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 658c88ee7414e82fa40a16b3ab809e2a8a7b58be6195927c6c83103d0a05988a
MD5 a9cfd638fb86017dd0b880f87b0dc6b8
BLAKE2b-256 ab0f9c9040f6445fb256579d8abd15d898e3b6472d90c613beff1fe8e25395e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page