All templatesTemplate
A document search API powered by RAG, pgvector, and LLM answers.
The RAG Search API template configures FastAPI AI Kit for retrieval-augmented generation applications. Ingest documents (PDF, Markdown, text), generate and store embeddings, and expose a semantic search endpoint that returns LLM-powered answers grounded in your data.
FastAPIpgvectorQdrantOpenAI EmbeddingsCeleryPostgreSQLRedis
What's included
- Document ingestion pipeline with configurable chunk size and overlap
- Embedding generation via OpenAI (text-embedding-ada-002)
- pgvector similarity search with cosine distance ranking
- Optional Qdrant integration (switch with one env var)
- LLM answer generation with retrieved context injection
- Background document processing via Celery workers
- Per-query token tracking for embedding + completion costs
- Auth, rate limiting, and Stripe billing pre-configured
Code preview
# Ingest a document (runs in background worker)
@router.post("/v1/documents/ingest")
async def ingest(body: IngestRequest, key: APIKey = Depends(verify_api_key)):
task = ingest_document_task.delay(
file_path=body.file_url,
collection=body.collection,
chunk_size=body.chunk_size or 512,
)
return {"task_id": task.id, "status": "processing"}
# Search with RAG-powered answers
@router.post("/v1/search")
async def search(body: SearchRequest, key: APIKey = Depends(verify_api_key)):
chunks = await rag.search(body.query, body.collection, top_k=5)
answer = await llm.chat(
messages=[
{"role": "system", "content": f"Answer using this context:\n{chunks}"},
{"role": "user", "content": body.query},
],
track_tokens=True, billing_key=key.id,
)
return {"answer": answer.content, "sources": chunks}Start with this template
Get FastAPI AI Kit, select this template configuration, and deploy your fastapi rag search api template in minutes.
Ready to ship your AI backend this weekend?
Join developers who skipped weeks of boilerplate and went straight to building.
No subscriptions · One-time payment · Lifetime updates