AI Recommendation Engine
Repository: bridges-ai-engine-source-code/oim-ai-recommandation-engine-staging
The AI engine is the heart of the platform. It is a FastAPI service that indexes opportunity documents into a vector store and generates personalized, explainable recommendations using Google Gemini.
Module Layout
Module |
Responsibility |
|---|---|
|
FastAPI application; exposes all REST endpoints (titled “RAG Vector Knowledge Base API”, version 1.0.0). |
|
Orchestrates recommendation generation by combining vector search with generative AI (Gemini via OpenRouter). |
|
Interface to Qdrant for semantic vector search; handles Ollama
|
|
PostgreSQL persistence layer with an optimized connection pool (v2.0). |
|
Python dependencies. |
|
Container build for deployment. |
FastAPI Application (main.py)
The main entry point exposes REST endpoints for document upload and indexing, recommendation generation, and analytics. Key endpoints:
Endpoint |
Purpose |
|---|---|
|
Upload and index a single document |
|
Index a batch of opportunities provided as JSON |
|
Generate recommendations for a single user |
|
Generate recommendations for a batch of users |
|
Various platform statistics |
See API Reference for full request/response schemas.
Gemini Agent (gemini_agent.py)
The agent orchestrates recommendation generation by combining vector search and the generative model. It supports the following opportunity types:
PERMANENT_EMPLOYMENT— permanent jobTEMPORARY_EMPLOYMENT— temporary jobVOCATIONAL_TRAINING— professional trainingENTREPRENEURSHIP— Income Generating Activity (IGA)INTERNSHIP— professional internship
For each request, the agent retrieves candidate opportunities from Qdrant using
the beneficiary’s profile, then prompts Gemini to rank and explain the most
relevant matches, returning a relevance_score (0.0–1.0) and a human-readable
reason for each.
PostgreSQL Memory (agent_memory.py)
Manages persistence in PostgreSQL using an optimized connection pool (v2.0). Main tables consumed by the engine:
Table |
Content |
|---|---|
|
Beneficiary profiles (stored as JSONB) |
|
Recommendation history and interaction tracking |
|
Conversation history (reserved for future use) |
The v2.0 improvements (connection pool, TCP keepalive, auto-reconnection, configurable SSL, 2–5× performance) are described in Configuration.
Qdrant Knowledge Base (qdrant_kb.py)
Provides the interface to Qdrant for semantic vector search. It uses Ollama
bge-m3 embeddings (1024 dimensions) and chunks documents to a maximum of 350
tokens before indexing. Collection statistics are available via
GET /collections/{name}/stats.
Indexing Workflow
Prepare documents (Word, PDF, JSON).
Upload via
/documents/uploador/documents/index-json-batch.The engine automatically extracts text, classifies it (GREEN/YELLOW/RED), and vectorizes it.
Verify with
GET /collections/{name}/stats.Opportunities are now searchable.
Recommendation Workflow
Retrieve the beneficiary profile.
Format it as JSON according to the schema in API Reference.
POST /recommendations/get22.Receive 5–10 ranked recommendations.
Recommendations are auto-saved to the database.
Display the results with their metadata.