How thinkany-ai/rag-search works
Project type and purpose
• This is a Python-based backend API service (monolithic FastAPI app) for Retrieval‑Augmented‑Generation (RAG) search.
• It exposes a REST endpoint (“/rag-search”) that:
– Takes a user query
– Runs a search via external search providers (e.g., Serper/Google, “search2ai”)
– Embeds/query documents in a vector database (Zilliz/Milvus)
– Optionally reranks results (FlashRank, LlamaIndex)
– Optionally summarizes/enhances with LLMs (OpenAI, Gemini, LingYi)
– Returns structured JSON responses
File structure
Top‑level folders and what they imply:
• components/ – cross‑cutting utilities (environment loader, logger)
• handlers/ – FastAPI route handlers implementing each API endpoint’s orchestration logic
• services/ – core business logic broken into subdomains:
– document/ (query & store vectors)
– llm/ (calls to different LLM providers)
– search/ (external search providers)
– rerank/ (result reranking logic)
– vdb/ (vector database client)
– web.py (wrapping service calls for HTTP)
• utils/ – small helpers (hashing, response formatting, sequence ops)
• main.py – application bootstrap (FastAPI app, router registration, dependency injection via service_context_factory)
• .env & requirements.txt – configuration and dependencies
Key insights from README
• Starts a FastAPI server on port 8069
• Relies on environment variables to wire in API keys, model names, Zilliz credentials, etc.
• Single HTTP POST endpoint (/rag-search) with request parameters controlling search provider, reranking, filtering, detail inclusion, etc.
Main components & their interactions
A. Client Layer:
– External Client (Postman/HTTP client)
B. API Layer (FastAPI)
– main.py: App + Router
– handlers/ (rag_search handler, ping, reranking)
– components/env.py & log.py (config + centralized logging)
C. Service Layer (Orchestration)
– Service Context Factory: builds and injects instances of all services
– services/search (calls out to Serper/Google, Search2AI)
– services/vdb (Zilliz vector store)
– services/document (stores/queries embeddings)
– services/rerank (FlashRank, LlamaIndex)
– services/llm (OpenAI, Gemini, LingYi clients)
– services/web (translating HTTP inputs into service calls)
D. Data & External Systems
– Zilliz/Milvus vector DB
– External Search APIs (Serper, Search2AI)
– LLM providers (OpenAI, Gemini, LingYi)
E. Utilities
– utils/* modules for common routines
Architectural patterns & design principles
• Layered architecture: clear separation between HTTP handling (handlers), business logic (services), and third‑party integrations (external APIs, DB).
• Dependency injection via a single ServiceContextFactory to make unit testing and swapping implementations easy.
• Modular design: each service subdomain is in its own package.
• Environment‑driven configuration: all sensitive keys and endpoints come from .env