This is a modular, production-ready backend built with FastAPI for managing users, documents, and AI-assisted semantic search. The project leverages PostgreSQL + pgvector, SQLAlchemy, Alembic, and integrates LangChain + OpenAI (GPT-4o) for powerful document-based LLM workflows.
- User Registration & Authentication:
- Register, login, and secure endpoints via token-based access control.
- Document Uploads & Management:
- Upload and manage documents via API.
- Each document is embedded and stored as a vector for semantic retrieval.
- Semantic Document Search:
- Vector-based document search using pgvector.
- Users can query for documents by meaning, not just keywords, via endpoints.
- LangChain & AI Agent Integration:
- The codebase is already integrated with LangChain and supports LLM-based workflows (e.g., OpenAI GPT-4o).
- Tools for natural language queries, summarization, and contextual search.
- Core logic in
app/agent/rag_agent.pyandrag_helper.py.
- DevContainer Support:
- Add
.devcontainer/with PostgreSQL & Python setup for VS Code.
- Add
- Pluggable AI Tooling:
- Extend
get_tools()to include OCR, summarization, translation, etc.
- Extend
- User Roles & Permissions:
- Add roles (admin, editor, viewer) with per-document permissions.
- Frontend Development:
- Build a basic React/Next.js frontend for UX.
- Performance Optimization & Deployment:
- Containerize the app with Docker, add production-ready settings, and prepare for cloud deployment (e.g., Railway, Azure, AWS).
Ensure you have the following installed:
- Python 3.12+
- PostgreSQL
- (Optional)
virtualenvorvenv
- Clone the repository:
git clone <repository-url> cd fastapi_project
- Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `.venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables (e.g.,
.envfile for database connection):DATABASE_URL=postgresql://user:password@localhost/dbname OPENAI_API_KEY=your-open-ai-key - Run database migrations:
alembic revision --autogenerate -m "migration commit message" alembic upgrade head
To start the FastAPI server, use:
uvicorn main:app --reload- Project uses pgvector for native similarity search in PostgreSQL.
- Designed for modular LLM agent workflows using LangChain + OpenAI.
- Core logic and agent tools can be extended easily for new AI capabilities.