Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Deep Engine - Heterogeneous Knowledge Base Engine

A cross-repository knowledge base engine with Agentic RAG capabilities for code, Markdown, and JSON.

License: MIT Python 3.10+

🎯 Overview

Deep Engine is an advanced knowledge base system designed for development teams, supporting:

  • Cross-Repository Querying: Search and reason across multiple codebases simultaneously
  • Heterogeneous Data: Unified handling of code (Python, JavaScript, Go), Markdown documentation, and JSON configurations
  • Agentic RAG: Intelligent query routing and planning with LangGraph
  • Hybrid Retrieval: Combines vector search (Qdrant) and graph traversal (Neo4j) with RRF fusion
  • Low Latency: Sub-800ms P95 query latency with intelligent query routing
  • Fine-Grained Permissions: Repository-level access control with OpenFGA (optional)

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Frontend Layer      β”‚  VS Code Plugin / Web UI
β”‚  (TypeScript)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ gRPC/HTTP
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  API Gateway         β”‚  FastAPI + OpenFGA
β”‚  (Python)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ gRPC
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Agentic Orchestratorβ”‚  LangGraph Workflow
β”‚  (Python)            β”‚  Router β†’ Planner β†’ Retriever β†’ ReRanker β†’ Generator
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ gRPC/Driver
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Storage Layer                   β”‚
β”‚  β”œβ”€ Qdrant (Vector Database)     β”‚  Dense + Sparse Vectors
β”‚  └─ Neo4j (Graph Database)       β”‚  Code Relationships
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ File/Event
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Ingestion Pipeline              β”‚
β”‚  β”œβ”€ Tree-sitter (Code Parsing)   β”‚
β”‚  β”œβ”€ unified (Markdown Parsing)   β”‚
β”‚  └─ JSON Parser                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Docker & Docker Compose (for local development)
  • OpenAI API Key (for embeddings)

1. Clone the Repository

git clone https://github.com/your-org/deep-engine.git
cd deep-engine

2. Set Up Python Environment

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

# Install dependencies
pip install -e ".[dev]"

3. Configure Environment

cp .env.example .env
# Edit .env and set your OPENAI_API_KEY

4. Start Infrastructure

# Start Qdrant and Neo4j
docker-compose up -d

# Wait for services to be healthy
docker-compose ps

5. Initialize Storage

python -m deep_engine.scripts.init_storage

6. Run the API Server

uvicorn deep_engine.api.main:app --host 0.0.0.0 --port 8000 --reload

Visit http://localhost:8000/docs for the interactive API documentation.

πŸ“š Core Concepts

Data Model: StructuredNode

All data (code, docs, JSON) is transformed into a unified StructuredNode:

{
    "node_id": "org/repo/path/to/file.py#abc123",
    "repo_id": "org/repo",
    "file_path": "path/to/file.py",
    "node_type": "function",
    "content": "def authenticate(user, password):",
    "metadata": {
        "language": "python",
        "line_start": 42,
        "line_end": 56
    },
    "relations": [
        {"type": "CALLS", "target": "org/repo/utils.py#validate"}
    ],
    "embedding_dense": [...],  # 384-dim vector
    "embedding_sparse": {...}  # Token IDs β†’ weights
}

Hybrid Retrieval

Reciprocal Rank Fusion (RRF) combines three retrieval sources:

  1. Dense Vector Search: Semantic similarity (Cosine)
  2. Sparse Vector Search: Keyword matching (IDF-weighted)
  3. Graph Traversal: Relationship-based navigation
# RRF Formula
score(node) = Ξ£(1 / (k + rank_i))  # k=60, across all sources

Agentic Workflow

graph TD
    Start([User Query]) --> Router{Router<br/>Simple or Complex?}
    Router -->|Simple| Retriever[Direct Retrieval]
    Router -->|Complex| Planner[Query Planner]
    Planner --> SubTasks[Parallel SubTask Execution]
    SubTasks --> Retriever
    Retriever --> ReRanker[Cross-Encoder ReRanker]
    ReRanker --> Generator[Answer Generator]
    Generator --> End([Response with Citations])
Loading

πŸ”§ Usage Examples

Indexing a Repository

from deep_engine.ingestion.pipeline import IngestionPipeline

pipeline = IngestionPipeline()
await pipeline.ingest_repository(
    repo_id="my-org/backend-api",
    repo_path="/path/to/repo",
    file_patterns=["**/*.py", "**/*.md", "**/*.json"]
)

Querying the Knowledge Base

from deep_engine.api.client import DeepEngineClient

client = DeepEngineClient(api_url="http://localhost:8000")

response = await client.query(
    query="Find all authentication functions that use UserSchema",
    repo_ids=["my-org/backend-api"],
    top_k=10
)

print(response.answer)
for citation in response.sources:
    print(f"  β†’ {citation.file_path}:{citation.line_start}")

REST API

# Query endpoint
curl -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -d '{
    "query": "How does authentication work?",
    "repo_ids": ["my-org/backend-api"],
    "top_k": 10
  }'

# Health check
curl http://localhost:8000/health

πŸ› οΈ Development

Project Structure

deep-engine/
β”œβ”€β”€ deep_engine/
β”‚   β”œβ”€β”€ api/                    # FastAPI application
β”‚   β”œβ”€β”€ ingestion/              # Data ingestion pipeline
β”‚   β”‚   β”œβ”€β”€ parsers/            # Code, Markdown, JSON parsers
β”‚   β”‚   β”œβ”€β”€ chunking/           # Semantic chunking
β”‚   β”‚   └── embedding/          # Vector generation
β”‚   β”œβ”€β”€ storage/                # Storage layer
β”‚   β”‚   β”œβ”€β”€ vector/             # Qdrant client
β”‚   β”‚   └── graph/              # Neo4j client
β”‚   β”œβ”€β”€ retrieval/              # Hybrid retrieval
β”‚   β”œβ”€β”€ orchestrator/           # Agentic workflow
β”‚   β”‚   β”œβ”€β”€ agents/             # Router, Planner, Generator
β”‚   β”‚   └── tools/              # Retrieval tools
β”‚   β”œβ”€β”€ models/                 # Pydantic schemas
β”‚   β”œβ”€β”€ config/                 # Configuration
β”‚   └── utils/                  # Logging, metrics
β”œβ”€β”€ tests/                      # Unit and integration tests
β”œβ”€β”€ docker-compose.yml          # Local development stack
β”œβ”€β”€ pyproject.toml              # Python dependencies
└── README.md

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=deep_engine --cov-report=html

# Run specific test file
pytest tests/unit/test_retrieval.py

Code Quality

# Format code
black deep_engine/

# Lint code
ruff check deep_engine/

# Type checking
mypy deep_engine/

πŸ“Š Monitoring

Prometheus Metrics

  • Query latency (P50, P95, P99)
  • Retrieval performance by type
  • Ingestion throughput
  • Storage operation metrics

Start monitoring stack:

docker-compose --profile monitoring up -d

Structured Logging

Logs are emitted in JSON format by default:

{
  "timestamp": "2024-12-13T10:30:45.123Z",
  "level": "info",
  "event": "query_completed",
  "query": "How does auth work?",
  "latency_ms": 245,
  "results_count": 10
}

πŸ” Security & Permissions

OpenFGA Integration (Optional)

Enable fine-grained authorization:

# Start with OpenFGA
docker-compose --profile with-openfga up -d

# Configure in .env
OPENFGA_API_URL=http://localhost:8080
OPENFGA_STORE_ID=your-store-id
OPENFGA_AUTH_MODEL_ID=your-model-id

Authorization model:

type user

type repo
  relations
    define reader: [user]
    define writer: [user]

🎯 Performance

Metric Target Actual (Local)
Query Latency (P50) < 300ms ~250ms
Query Latency (P95) < 800ms ~650ms
Ingestion Throughput > 10 files/sec ~15 files/sec
Supported Repos 1000+ Tested up to 100

πŸ—ΊοΈ Roadmap

Phase 1: MVP βœ… Complete

  • Core data models
  • Qdrant + Neo4j storage
  • Hybrid retrieval with RRF
  • Basic API gateway
  • Docker Compose setup

Phase 2: Alpha βœ… Complete (5/5)

  • Code parser (Tree-sitter for Python, JS/TS)
  • Markdown parser with enhanced metadata
  • JSON parser with JSONPath and schema support
  • Agentic orchestrator (LangGraph workflow)
    • Router agent (simple/complex classification)
    • Planner agent (LLM-powered decomposition)
    • Retrieval manager (parallel execution)
    • Generator agent (GPT-3.5 synthesis)
  • VS Code plugin (deferred to future release)

Phase 3: Beta 🚧 (2/4 Complete)

  • Cross-encoder reranking (20-30% precision improvement)
  • Incremental indexing (content-hash based)
  • Query caching (Redis with TTL)
  • Multi-modal support (images, diagrams) (planned)

Phase 4: Production πŸ“‹ (Planned)

  • OpenFGA integration for fine-grained authorization
  • Horizontal scaling configuration
  • Advanced monitoring (OpenTelemetry tracing)
  • Enterprise SSO (SAML/OAuth)

Current Status: v0.3.0 Beta - Production-Ready Core

Completion: 75% of roadmap features (7/14 major tasks)
Next Priority: Testing suite, VS Code plugin, multi-modal support

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“§ Contact


Built with ❀️ for developers who love knowledge

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages