Skip to main content

Cléa-API: A framework for document load and hybrid search engine combining vector and metadata-based search. CRUD operations are performed using FastAPI.

Project description

Cléa-API 🚀

Hybrid document-search framework for PostgreSQL + pgvector

Licence MIT Docs

Cléa-API charge des documents multi-formats, les segmente, les vectorise et fournit une recherche hybride (vectorielle + filtres SQL) prête à l'emploi. Il s'utilise :

  • via endpoints REST (FastAPI) ;
  • en librairie Python (extraction, pipeline, recherche) ;
  • avec une base PostgreSQL + pgvector auto-indexée par corpus ;
  • 100% local et hors-ligne pour vos données sensibles.

Sommaire rapide

Sujet Documentation
Chargement & extraction Extracteurs · Segmentation
Base de données & index vectoriels Database
Moteur de recherche hybride Search
Pipeline end-to-end Pipeline
Référence API Python (autogen) Doc Loader · Vectordb · Pipeline
IA génératrice (RAG) AskAI
Stats Stats
OpenAPI / Endpoints REST REST API

Caractéristiques clés

  • 🔒 100% local & hors-ligne : traitement sécurisé pour données confidentielles

  • 🔄 Chargement multi-formats : PDF, DOCX, HTML, JSON, TXT, …

  • 🧩 Segmentation hiérarchique : Section ▶ Paragraphe ▶ Chunk

  • 🔍 Recherche hybride : ivfflat ou HNSW + Cross-Encoder rerank

  • 🤖 RAG avec petits LLMs : génération augmentée via modèles Qwen3 légers

  • Pipeline "one-liner" :

    from pipeline import process_and_store
    from askai.src.rag import RAGProcessor
    
    # Traitement de documents
    process_and_store("rapport.pdf", theme="R&D")
    
    # Interrogation des documents via RAG
    response, context = rag_processor.retrieve_and_generate(
        "Quelles sont les principales recommandations du rapport?"
    )
    
  • 📦 Architecture modulaire : ajoutez un extracteur ou un modèle en quelques lignes

  • 🐳 Docker-ready & CI-friendly (tests PyTest, docs MkDocs)


Options de lancement

Cléa-API supporte plusieurs modes de lancement avec différentes options de configuration:

# Mode standard
./start.sh

# Mode développeur avec logs détaillés
uv run main.py --debug

# Configuration avancée
uv run main.py --host 0.0.0.0 --port 9000 --workers 4

# Avec variables d'environnement
API_LOG_LEVEL=debug API_PORT=9000 ./start.sh

Niveaux de journalisation

Le système de logs est centralisé et configurable:

Mode Description Commande
INFO (défaut) Informations essentielles uv run main.py
DEBUG Détails techniques uv run main.py --debug
WARN/ERROR Uniquement alertes et erreurs API_LOG_LEVEL=warning uv run main.py

Les logs suivent le format standard:

2025-05-04 16:30:21,483 - clea-api.doc_loader - INFO - Document chargé: demo.pdf (3.2MB)

Arborescence du dépôt

.
├── doc_loader/   # Extraction & chargement de documents
├── vectordb/     # Modèles SQLAlchemy + recherche 
├── pipeline/     # Orchestrateur end-to-end
├── askai/        # Génération RAG avec modèles légers
├── docs/         # Documentation MkDocs
├── demo/         # Fichiers d'exemple
├── start.sh      # Script de démarrage API
├── Dockerfile    # Build image
└── ...

Installation

Prérequis

  • Python ≥ 3.11
  • PostgreSQL ≥ 14 avec l'extension pgvector
  • (Recommandé) WSL 2 + openSUSE Tumbleweed

Installation sur openSUSE Tumbleweed

# 1. Installer les dépendances système
sudo zypper install postgresql15 postgresql15-server postgresql15-devel python311 python311-devel gcc

# 2. Activer PostgreSQL
sudo systemctl enable postgresql
sudo systemctl start postgresql

# 3. Installer uv (gestionnaire de paquets Python moderne)
curl -sSf https://astral.sh/uv/install.sh | sh

Installation de Cléa-API

# 1. Cloner
git clone https://github.com/<your-gh-user>/clea-api.git
cd clea-api

# 2. Dépendances (avec uv)
uv pip install -r requirements.txt

# 3. Pour le module askai (optionnel)
uv pip install -r askai/requirements_askai.txt

# 4. Variables d'environnement
cp .env.sample .env   # puis éditez au besoin

# 5. Initialisation DB et extension pgvector
uv python -m vectordb.src.database init_db

# 6. Lancer l'API
uv run main.py           # ➜ http://localhost:8080

Utilisation express

Chargement simple

curl -X POST http://localhost:8080/doc_loader/upload-file \
     -F "file=@demo/devis.pdf" -F "theme=Achat"

Pipeline complet (upload → segment → index)

curl -X POST http://localhost:8080/pipeline/process-and-store \
     -F "file=@demo/devis.pdf" -F "theme=Achat" -F "max_length=800"

Recherche hybride

curl -X POST http://localhost:8080/search/hybrid_search \
     -H "Content-Type: application/json" \
     -d '{"query":"analyse risques", "top_k":8}'

Génération RAG (AskAI)

curl -X POST http://localhost:8080/askai/query \
     -H "Content-Type: application/json" \
     -d '{
       "question": "Résumer les points importants du document", 
       "theme": "Achat", 
       "enable_thinking": true
     }'

Utilisation en mode streaming

curl -N -X POST http://localhost:8080/askai/query_stream \
     -H "Content-Type: application/json" \
     -d '{"question": "Expliquer la structure du document"}'

Sécurité et confidentialité

Cléa-API est conçu pour traiter des données sensibles et confidentielles avec une approche orientée sécurité:

  • 100% hors-ligne: aucune donnée n'est envoyée vers des services externes
  • Modèles légers locaux: tous les LLMs sont exécutés localement (Qwen3-0.6B/1.7B)
  • Aucune télémétrie: pas de tracking ni d'analytics
  • Aucune dépendance cloud: fonctionne en environnement air-gapped

Cette approche est idéale pour les organisations avec des contraintes strictes de confidentialité (données médicales, financières, juridiques, etc.).


Tests

uv run pytest           # tous les tests unitaires

Déploiement Docker

docker build -t clea-api .
docker run -p 8080:8080 clea-api

Contribuer 🤝

  1. Fork → branche (feat/ma-feature)
  2. uv run pytest && mkdocs build doivent passer
  3. Ouvrez une Pull Request claire et concise

Licence

Distribué sous licence MIT – voir LICENSE.

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

clea_api-0.2.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

clea_api-0.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file clea_api-0.2.1.tar.gz.

File metadata

  • Download URL: clea_api-0.2.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for clea_api-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2d55373c8e6447041e0632050673be80d012c48f157beab18ca0a45ed3f46064
MD5 917d27b67b8919b8b2f39791bddb861f
BLAKE2b-256 05f2bc6db316efda20d88e954e0483459eebec38c6f511ae81bf89fbde6ac311

See more details on using hashes here.

File details

Details for the file clea_api-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: clea_api-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for clea_api-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b92710bd5f5574e2d7eb02b7efa944ad9f293f177d8270c8dc1885ef3f4e0075
MD5 375a6fdd96285de93b967d74e12ca2fd
BLAKE2b-256 0573a06fe21e0c70f488ea9724f5c9079aade48de937caf033d2c7f43cffaeb7

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