How shukla-abhinav/fastapi-ollama-qa works
Project Overview and Main Components
• The system is a backend application built with FastAPI to manage documents and enable Retrieval-Augmented Generation (RAG) based question answering using Llama 2.
• It employs Docker for containerization and uses PostgreSQL as the primary database.
• The architecture is structured into distinct components: API layer, business/service layer, database layer (with SQLAlchemy models and migrations via Alembic), and utility/configuration layers.
Identifying Key Components
a. API Layer (app/api/):
• Use clear labels for each endpoint grouping (Documents, QA, Users).
b. Service Layer (app/services/):
• Business logic handling document service and QA service (e.g., document_service.py and qa_service.py).
• These components orchestrate processes like generating document embeddings (with Sentence Transformers) and interfacing with the Llama 2 model for question answering.
c. Database Layer (app/db/ and app/models/):
• PostgreSQL database along with SQLAlchemy models.
• Alembic migrations (alembic/ folder and alembic.ini) managing schema changes.
• Database session management (via app/db/database.py).
d. Containerization and Deployment:
• Dockerfile and docker-compose.yml components. These should encapsulate overall application deployment, indicating containerized microservices or services running in Docker.
• Optionally reference configuration files (setup.py, requirements.txt) that support building the container images.
Illustrating Relationships and Data Flow
• From the API layer, show data flowing to the service layer which processes business logic.
• From the service layer, include interactions with the database layer (CRUD operations performed via SQLAlchemy models).
• For document embeddings and QA processes, highlight a flow from the service layer to external machine learning components, such as Sentence Transformers for embeddings and the Llama 2 model for question/answer generation.
Architectural Patterns and Design Principles
• Clearly separate concerns using the Clean Architecture pattern. Each layer (API, services, database) should be self-contained.
• Asynchronous API design, especially if there’s any use of async routines in FastAPI endpoints.
• That the application is built as a microservice-like modular structure even within a monolithic deployment facilitated by Docker.
Relevant Technologies and Frameworks to be Noted
• FastAPI for routing and API management.
• SQLAlchemy for ORM in the models folder.
• Alembic for database migrations.
• Docker and Docker Compose for container orchestration.
• Sentence Transformers and Llama 2 for document embedding and RAG-based question answering, respectively.