How pallavi2908/semantra works
Project Type and Purpose
• Semantra is a full-stack AI-powered medical‐query assistant.
• It consists of a static frontend (HTML/CSS/JS) served by a FastAPI backend on Uvicorn, which handles queries by retrieving semantically relevant chunks from a Qdrant vector store and invoking an LLM (Mistral 7B) for response generation.
File Structure
• Top-level scripts (create_chunks.py, convert_nested_to_flat.py, embeddings.py, merge_embeddings.py, importVectors.py, upload_to_qdrant.py) implement the offline data-ingestion and indexing pipeline.
• api.py / main.py define the FastAPI app and HTTP endpoints.
• qdrant.py encapsulates interactions with the Qdrant vector database.
• static/ holds the HTML/CSS frontend, which makes POST requests to /query.
• GitHub Actions (/.github/workflows/main.yml) pings the server to prevent idling on Render.
Architecture from the README
• Backend: FastAPI + Uvicorn, Qdrant vector DB replacing Weaviate, Mistral 7B LLM.
• Frontend: Static HTML/CSS with JavaScript fetch calls to /query.
• Deployment: Hosted on Render; CI/CD pinger via GitHub Actions.
Main Components & Interactions
a. Components
• Client Browser (User Interface)
• Static Assets (index.html, styles.css, JS)
• FastAPI Server (api.py)
• Qdrant Vector Database
• LLM Inference Engine (Mistral 7B)
• Data-Ingestion Pipeline (Python scripts + raw research papers)
• CI/CD Keep-Alive Service (GitHub Actions)
• Cloud Hosting (Render)
b. Relationships & Data Flow
1. User enters a query in the browser → JS POSTs to FastAPI /query endpoint.
2. FastAPI receives the query → calls qdrant.py to perform a vector search over embeddings stored in Qdrant.
3. Retrieved chunks + original query → sent to the LLM inference engine for answer generation.
4. LLM response → formatted by FastAPI → returned to the client.
5. Offline Pipeline: Raw documents → chunking → embedding generation → merged and imported into Qdrant.
6. GitHub Actions periodically pings the FastAPI endpoint to keep Render’s free instance alive.
c. Architectural Patterns & Principles
• Separation of concerns: static frontend vs. API vs. vector store vs. LLM.
• Asynchronous, non-blocking I/O via Uvicorn/ASGI.
• Modular ingestion pipeline for data updates.
d. Key Technologies
• FastAPI, Uvicorn, Qdrant, Mistral 7B, Python (requests, pandas, scikit-learn), Render, GitHub Actions.