The rag-core-api contains the API layer for the RAG template for document retrieval, question answering, knowledge base management in the vector database and more.
Project description
rag-core-api
High-level API layer for the STACKIT RAG-Template. It transforms its own primitives and those from rag-core-lib into a production-ready FastAPI surface, exposing chat, evaluation, and document-management endpoints used by services/rag-backend and the MCP server of the RAG-Template.
Responsibilities
- Dependency Injection – Compose the dependency-injector container to assemble LLMs, embeddings, vector stores, rerankers, and retrievers from
rag-core-lib. - API Exposure – Expose production-ready FastAPI routers for chat, evaluation, and information piece management.
- Chat Orchestration – Provide default LangGraph chat orchestration and evaluation pipelines that downstream services can reuse or override.
- Knowledge base integration – Manages all interaction with the knowledge base (vector database).
Feature highlights
- Chat graph built on LangGraph – Default
DefaultChatGraphstitches together language detection, question rephrasing, retrieval (with reranking), answer generation, and Langfuse tracing. - Evaluation endpoint – Ships a Langfuse + RAGAS evaluator so you can score QA datasets against your RAG stack without custom plumbing.
- Pluggable components – Replace embedder, vector database, reranker, prompts, or chains via dependency-injector overrides. The defaults target Qdrant + FlashRank but every interface is typed.
- Consistent models – Pydantic schemas in
rag_core_api.modelscover request/response payloads for chat, evaluation, and document ingestion. - Shared configuration – Reuses
rag-core-libsettings so LLMS, embeddings, retries, and Langfuse behave the same way across services.
Installation
pip install rag-core-api
Requires Python 3.13 and rag-core-lib.
Where it fits in the RAG solution
| Layer | Responsibilities | Package |
|---|---|---|
| RAG primitives | LLMs, embeddings, retry, tracing (shared in multiple libs) | rag-core-lib |
| API assembly (this package) | Routers, dependency container, evaluators, graph wiring | rag-core-api |
| Service runtime | FastAPI application to customize the API offered by rag-core-api |
services/rag-backend |
Other services (admin backend and MCP server) call the endpoints provided by this package to ingest, delete, and chat with information pieces.
Module tour
dependency_container.py– Configures dependency-injector providers. Override registrations here to swap providers or inject fakes for tests.api_endpoints/&impl/api_endpoints/– Thin endpoints + abstractions (Chat,InformationPiecesUploader, etc.) that map HTTP verbs to underlying logic.api/– Core API definitions, mostly created by API-specs and openapi generator.embeddings/&impl/embeddings/– Embedding classes + abstractions + embedder type definitions.evaluator/&impl/evaluator/– Langfuse + RAGAS evaluator used by/evaluateendpoint.graph/&impl/graph/– LangGraph graph + state definitions for chat flows, including language detection, rephrasing, retrieval etc.reranking/&impl/reranking/– Reranking logic for selecting most relevant documents.retriever/&impl/retriever/– Document retrieval logic.impl/settings/– Configuration settings for dependency injection container components.mapper/– Information piece 2 langchain documents mapper.prompt_templates/– Default LLM prompts for answering, rephrasing, and language detection. Override them via Langfuse or dependency injection.embeddings/– Thin wrappers that adapt embedder instances fromrag-core-libfor retriever usage. They will be removed in v4.utils/– Shared utility functions and classes.vector_databases/&impl/vector_databases/– Interfaces plus default implementations (Qdrant, FlashRank).
Endpoints provided
POST /chat/{session_id}– Conversational RAG (streaming and non-streaming depending on transport). Handles language detection, retrieval, and answer generation.POST /evaluate– Runs RAGAS evaluation on supplied question/answer datasets; outputs Langfuse traces and aggregate metrics.POST /information_pieces/upload– Accepts pre-extracted (e.g., fromextractor-api-lib) and processed (e.g., fromadmin-api-lib) documents for ingestion into the vector store.POST /information_pieces/remove– Removes stored information pieces by document identifier from the vector store.
Refer to libs/README.md for in-depth API documentation.
Configuration overview
rag-core-api consumes the same environment variables as rag-core-lib for provider selection (RAG_CLASS_TYPE_LLM_TYPE, EMBEDDER_CLASS_TYPE_EMBEDDER_TYPE, Langfuse keys, retry settings). Additional knobs include:
QDRANT_URL,QDRANT_API_KEY,QDRANT_COLLECTION_NAME– passed into the defaultQdrantDatabase.FLASHRANK_MODEL_NAME– tuner for FlashRank reranker.RAGAS_DATASET_FILENAME,RAGAS_MODEL– control evaluation dataset and LLM.
The Helm chart supplies these values through backend.envs.*. Local development can rely on .env configuration (see repository root documentation).
Typical usage
from rag_core_api.main import app as perfect_rag_app
Delivers a full functional API. See services/rag-backend/main.py and services/rag-backend/container.py, which compose the API with additional middleware, auth, and deployment-specific wiring.
Extending the library
- Subclass the relevant interface (e.g.,
VectorDatabase,Retriever,Chatendpoint). - Register your implementation in the dependency container.
- Add pytest-based tests under
libs/rag-core-api/teststhat exercise the new component via the container.
Because components depend on interfaces defined here, downstream services can swap behavior without modifying the public API surface.
Contributing
Ensure new endpoints or adapters remain thin and defer to rag-core-lib for shared logic. Run poetry run pytest and the configured linters before opening a PR. For further instructions see the Contributing Guide.
License
Licensed under the project license. See the root LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rag_core_api-4.2.0.tar.gz.
File metadata
- Download URL: rag_core_api-4.2.0.tar.gz
- Upload date:
- Size: 38.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5e90ac1fd298d29f63672c780a5afb16628c932a3647c808e51397f902a0198
|
|
| MD5 |
49bd04003bddfd122155f958556e1184
|
|
| BLAKE2b-256 |
83dbb2c5921f677c998ada88f67c870a12dd6b144264a0ce64261329438b7bb1
|
File details
Details for the file rag_core_api-4.2.0-py3-none-any.whl.
File metadata
- Download URL: rag_core_api-4.2.0-py3-none-any.whl
- Upload date:
- Size: 66.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e26750de1e794f3c6731395bcc3c7559f0d58c2a870bacfabd289f86b788da41
|
|
| MD5 |
9489cbc78cc567cf6fbbb73ece31c664
|
|
| BLAKE2b-256 |
3b35f0619caafde6b7a16cb391e665ff846f3b0d8f2973f60943b35dce38b13b
|