Spaces:
Runtime error
Runtime error
metadata
title: Knowledge Engine
emoji: π
colorFrom: purple
colorTo: gray
sdk: docker
app_port: 7860
license: apache-2.0
pinned: false
π Knowledge Engine
High-performance Hybrid Search & Reranking Engine based on BGE-M3. > An advanced knowledge retrieval API system that combines Dense/Sparse embeddings and optimizes precision with Cross-Encoders.
π Key Features
- Hybrid Search: Seamlessly combines Dense & Sparse vector retrieval using Qdrant's Native Fusion API (BGE-M3).
- Re-ranking: Ensures top-tier precision by re-ordering search results via Cross-Encoder models.
- Clean Architecture: Highly modularized layers (API, Service, Storage, Models) for superior maintainability and scalability.
- CI/CD Pipeline: Fully automated deployment to Hugging Face Spaces using GitHub Actions and Docker.
- Auto-Healing Data: Robust startup logic via FastAPI
lifespanthat automatically synchronizes and validates the knowledge base.
π Project Structure
This project follows the Separation of Concerns (SoC) principle to ensure the system remains extensible and testable.
βββ api/ # API Routing & Dependency Injection (DI)
βββ core/ # Global Configuration (Pydantic Settings) & Exception Handling
βββ models/ # AI Model Inference (Embedder, Reranker)
βββ services/ # Business Logic & Search Pipeline Orchestration
βββ storage/ # Infrastructure Layer (Qdrant, SQLite Clients)
βββ scripts/ # Data Pipeline & Database Setup Scripts
βββ templates/ # Demo UI (Jinja2 Templates)
βββ main.py # App Entry Point & Lifespan Management
π Tech Stack
- Framework: FastAPI
- Vector DB: Qdrant (Local Path Mode)
- RDBMS: SQLite (Metadata & Corpus Storage)
- ML Models:
BAAI/bge-m3(Multi-functional Embedding)BAAI/bge-reranker-v2-m3(Cross-Encoder)
- DevOps: Docker, GitHub Actions, Hugging Face Hub
π§ Installation & Setup
Prerequisites
- Python 3.10 or higher
- Hugging Face Access Token (Read/Write)
Running Locally
- Clone the repository:
git clone [https://github.com/m97j/knowledge-engine.git](https://github.com/m97j/knowledge-engine.git) cd knowledge-engine - Install dependencies:
pip install -r requirements.txt - Run the application (The system will automatically download the necessary DB files on startup):
python main.py # OR using uvicorn uvicorn main:app --host 0.0.0.0 --port 7860
π‘ API Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Redirects to Search Demo UI |
POST |
/api/v1/search/ |
Executes JSON-based Hybrid Search |
GET |
/api/v1/system/health/ping |
System health check (Heartbeat) |
π‘ Architecture Insights
- Dependency Injection: Uses FastAPI
app.stateto manage singletons of AI models and DB clients, allowing for easy mocking during unit testing. - Hybrid RAG Pipeline: Beyond simple vector similarity, this engine leverages Sparse embeddings for keyword-level precision, merged via Reciprocal Rank Fusion (RRF).
- Deployment Ready: Optimized for PaaS environments (like HF Spaces) through a containerized Docker setup and automated CI/CD.
π Documentation
For more detailed technical documentation, design decisions, and troubleshooting, please visit: