How dv1712/clinicscribe works
Purpose and Entry Points
ClinicScribe is a Python RAG prototype for answering medical-literature questions from a local textbook corpus. The interactive application entry point is clinicScribe.py. Offline knowledge-base preparation is separated into create_memory_for_llm.py and connect_memory_with_llm.py.
Source Knowledge Corpus
The initial authoritative source is a local medical PDF: data/The_GALE_ENCYCLOPEDIA_of_MEDICINE_SECOND.pdf. It is loaded, text-extracted, and chunked during indexing rather than queried directly at chat time. The system is explicitly educational/research-oriented, not a clinical diagnostic system.
Indexing and Embedding Stage
create_memory_for_llm.py builds the retrieval memory: document chunks are converted into HuggingFace embedding vectors and persisted as a FAISS index. This is the offline boundary between expensive document processing and interactive question answering.
Persisted artifacts are under:
• vectorstore/db_faiss/index.faiss
• vectorstore/db_faiss/index.pkl
These files allow the serving path to reuse indexed content without reprocessing the PDF.
Retrieval and Generation Pipeline
connect_memory_with_llm.py connects the persisted FAISS store to the LLM-facing RAG chain. For each user question, the pipeline performs similarity retrieval over embedded textbook chunks, supplies retrieved context to the language model, and returns a grounded generated response.
This component is the main integration boundary between LangChain orchestration, HuggingFace embedding/model access, FAISS retrieval, and Groq-accelerated inference.
Interactive Application Layer
clinicScribe.py provides the Streamlit chat interface. It accepts user questions, invokes the configured retrieval/LLM pipeline, and renders responses. It should consume the existing vector store at vectorstore/db_faiss/ rather than own indexing responsibilities.
Runtime and External Dependencies
The project runs as a Python application with Streamlit as the UI runtime. LangChain coordinates document retrieval and prompt/LLM flow; FAISS provides local vector similarity search; HuggingFace supplies open-source model or embedding access; Groq is the external accelerated LLM inference service. Network/API credentials are therefore likely required for the inference path, while corpus and vector index storage are local.
Primary Control Flow
1. Run create_memory_for_llm.py when the source PDF or embedding strategy changes.
2. Persist embeddings and chunk metadata to vectorstore/db_faiss/.
3. Start clinicScribe.py for interactive use.
4. User question flows through connect_memory_with_llm.py-style RAG wiring: retrieve FAISS neighbors, construct LLM context, invoke inference, display answer.
Main entry points: connect_memory_with_llm.py RAG chain wiring · create_memory_for_llm.py Memory builder · clinicScribe.py ClinicScribe chat UI · index.faiss FAISS vector index
Components 13
Offline indexing
Rebuild when the corpus or embedding strategy changes.
- Medical textbook PDF · Educational and research source material.
data/The_GALE_ENCYCLOPEDIA_of_MEDICINE_SECOND.pdf - Memory builder · Extracts text, chunks documents, and creates embeddings.
create_memory_for_llm.py - FAISS vector index · Persisted vectors and chunk metadata reused by serving.
vectorstore/db_faiss/index.faiss - FAISS metadata
vectorstore/db_faiss/index.pkl
Interactive RAG
- ClinicScribe chat UI · Interactive entry point for literature questions.
clinicScribe.py - User
- RAG chain wiring · Loads the store, retrieves context, and invokes the LLM.
connect_memory_with_llm.py - Similarity retrieval
- Grounded context · Supplies retrieved textbook chunks to inference.
- Generated answer · Rendered as educational/research output, not diagnosis.
External services
- HuggingFace embeddings
- LangChain
- Groq inference · Requires network access and API credentials.
Connections 17
- Medical textbook PDF → Memory builder: extract and chunk
- Memory builder → HuggingFace embeddings: create vectors
- HuggingFace embeddings → Memory builder: embeddings
- Memory builder → FAISS vector index: persist vectors
- Memory builder → FAISS metadata: persist chunk metadata
- User → ClinicScribe chat UI: asks question
- ClinicScribe chat UI → RAG chain wiring: invoke RAG
- RAG chain wiring → FAISS vector index: load existing store
- RAG chain wiring → FAISS metadata: load metadata
- RAG chain wiring → LangChain: orchestrate chain
- LangChain → Similarity retrieval: run retrieval
- Similarity retrieval → FAISS vector index: similarity search
- Similarity retrieval → Grounded context: retrieved chunks
- Grounded context → Groq inference: grounded prompt
- Groq inference → RAG chain wiring: generated response
- RAG chain wiring → Generated answer: return answer
- Generated answer → ClinicScribe chat UI: render