Spaces:
Sleeping
Download backend/README.md from orakzai-io/Rednote: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/orakzai-io/Rednote/resolve/main/backend/README.md
- Command line
-
hf download hf://spaces/orakzai-io/Rednote/backend/README.md
-
curl -L -o README.md https://huggingface.co/spaces/orakzai-io/Rednote/resolve/main/backend/README.md
RAG Backend API (FastAPI)
This is the FastAPI backend serving the Document Assistant application. It handles user authentication, document parsing (PDF/TXT), vector embeddings creation using fastembed, and RAG-based chat using the Groq SDK.
Key Technologies
- FastAPI: Modern, fast web framework for building APIs.
- SQLAlchemy & Alembic: Database ORM and migrations helper.
- PostgreSQL + pgvector: Relational database with vector similarity search capabilities.
- FastEmbed: Lightweight, fast library for generating text embeddings (default:
BAAI/bge-small-en-v1.5). - PyMuPDF (fitz): Optimized library for parsing PDFs and extracting text.
- Groq SDK: Connects to the Groq Cloud API for fast llama3 text completions.
- FastAPI Users: Authentication system using JWT tokens.
Getting Started (Local Development)
Prerequisites
- Python 3.12+
- Running PostgreSQL database with
pgvectorextension enabled
Setup Steps
Navigate to backend directory
cd backendCreate a virtual environment & install dependencies
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txtConfigure Environment Variables Create a
.envfile based on.env.examplein the root or copy/rename it:cp .env.example .envModify
.envto configure yourDATABASE_URL,GROQ_API_KEY, andSECRET_KEY.Run Database Migrations / Initialize DB The application automatically initializes database tables on startup.
Start Development Server
uvicorn main:app --reload --port 8000Open http://localhost:8000/docs in your browser to view the interactive Swagger API documentation.
Testing
Run unit and integration tests using pytest:
pytest
Tests are located in the tests/ directory.