# ID-based RAG FastAPI

An asynchronous FastAPI service that indexes and retrieves document embeddings by file ID using Langchain and PostgreSQL with pgvector, built primarily to back LibreChat but usable for any ID-based retrieval case.

ID-based RAG FastAPI integrates Langchain with FastAPI asynchronously to provide document indexing and retrieval backed by PostgreSQL and pgvector. Files are organized into embeddings by file_id, which allows file-level querying when combined with file metadata stored separately, and the API is built to evolve its querying, reranking, embedding models and vector store over time. It offers asynchronous document management, adding, retrieving and deleting documents, on top of Langchain's vector store abstraction.

Its retrieval scope is owner-based: every route that reads or removes stored content resolves the caller's owner set from a verified token and applies it before ranking, so content outside that set is never read into the process, with the owner set derived from one shared module rather than re-implemented per route. A documented fix closed several prior authorization gaps, including an endpoint that listed every file ID in a deployment and a query endpoint that authorized an entire result set from only its first-ranked hit.

Its primary use case is as the retrieval backend for LibreChat, though the API is general enough for any file-ID-based retrieval use case.

Website: https://github.com/LibreChat-AI/rag-api
