How arjunisaac/policy-rag works
Purpose and Entry Points
Policy-RAG is a local insurance-policy question-answering system. It indexes a policy document library, retrieves relevant content, and uses a locally served Qwen3 model to generate answers and extract policy attributes.
Primary entry points:
• ingest_library.py builds or refreshes the searchable policy corpus.
• main.py launches the Streamlit user interface.
• vllm_env.sh prepares Linux environment settings for the separate vLLM inference server.
Runtime Topology
The application runs as two cooperating processes:
• Streamlit hosts the interactive RAG application via main.py.
• vLLM exposes an OpenAI-compatible API serving Qwen/Qwen3-4B-AWQ, configured externally through the README launch command and vllm_env.sh.
The Python application depends on the model service being available before query processing. Hugging Face authentication may be required to obtain gated model artifacts.
Ingestion and Corpus Boundary
Library ingestion is isolated from interactive querying:
• ingest_library.py
• src/ingestor.py
• src/vector_store.py
The ingestion path loads policy-library content, prepares it for retrieval, and persists/vectorizes it through the vector-store layer. This creates the durable boundary between raw policy documents and query-time retrieval; the Streamlit process should consume the indexed corpus rather than reprocess source documents per request.
Retrieval and RAG Orchestration
Query-time retrieval is split between retrieval infrastructure and policy-specific orchestration:
• src/retrieval.py
• src/vector_store.py
• src/policy_chain.py
retrieval.py and vector_store.py form the document-search boundary. policy_chain.py is the likely composition layer that turns a user question plus retrieved policy context into a model request and final response. It is the primary control-flow boundary between UI interaction, evidence retrieval, and LLM generation.
Attribute Extraction Pipeline
The repository contains a dedicated structured-extraction subsystem rather than relying solely on free-form RAG answers:
• src/extract_attribute/extraction_engine.py
• src/extract_attribute/retrieval_engine.py
• src/extract_attribute/post_processor.py
This subsystem retrieves relevant policy evidence for a target attribute, runs extraction, then normalizes or validates output in post-processing. Supporting strategies include regex extraction and summarization:
• src/extract_attribute/regex_extractor.py
• src/extract_attribute/summary_engine.py
This separation enables deterministic or hybrid extraction for policy fields where generated prose alone is insufficient.
Domain Model and Presentation Boundary
Shared policy concepts, types, and output formatting are centralized outside the UI and retrieval implementations:
• src/concepts.py
• src/datatypes.py
• src/formatting.py
main.py should remain the presentation/controller boundary, coordinating user input with the policy chain and extraction capabilities. styles.css supplies UI styling without participating in core retrieval or model logic.
Key Data Flow
1. ingest_library.py invokes ingestion and vector-store persistence for policy documents.
2. A user submits a question through main.py.
3. The policy chain retrieves relevant indexed policy passages.
4. Retrieved context and the user query are sent to the vLLM-hosted Qwen model.
5. The response is formatted for Streamlit; attribute-oriented requests may pass through the dedicated retrieval → extraction → post-processing pipeline.
Main entry points: extraction_engine.py Extraction engine · policy_chain.py Policy chain · main.py Streamlit app · retrieval_engine.py Attribute retrieval
Components 19
Corpus ingestion
Builds the durable searchable policy corpus.
- Policy document library · Raw policy content indexed offline.
- Ingestion entry point
ingest_library.py - Content ingestor
src/ingestor.py - Vector store · Persists embeddings and serves policy passage search.
src/vector_store.py
Interactive RAG
Serves questions against the indexed corpus.
- Streamlit app · Interactive application entry point.
main.py - UI styles
styles.css - Policy chain · Combines questions, retrieved evidence, and model responses.
src/policy_chain.py - Document retrieval
src/retrieval.py - Response formatting
src/formatting.py - Policy concepts
src/concepts.py - Shared data types
src/datatypes.py
Attribute extraction
Produces normalized structured policy fields.
- Attribute retrieval · Finds evidence for a requested policy field.
src/extract_attribute/retrieval_engine.py - Extraction engine
src/extract_attribute/extraction_engine.py - Regex extractor
src/extract_attribute/regex_extractor.py - Summary engine
src/extract_attribute/summary_engine.py - Post-processor · Normalizes or validates extracted attributes.
src/extract_attribute/post_processor.py
Model serving
Separate local inference process.
- vLLM environment · Prepares Linux settings for model serving.
vllm_env.sh - vLLM API · Serves the local Qwen/Qwen3-4B-AWQ model.
- Qwen3 model · May require Hugging Face authentication for artifacts.
Connections 23
- Policy document library → Ingestion entry point: source content
- Ingestion entry point → Content ingestor: invokes
- Content ingestor → Vector store: vectorizes and persists
- Streamlit app → UI styles: applies
- Streamlit app → Policy chain: user question
- Policy chain → Document retrieval: requests evidence
- Document retrieval → Vector store: searches indexed corpus
- Policy chain → vLLM API: query and context
- vLLM API → Qwen3 model: serves
- vLLM environment → vLLM API: configures
- Policy chain → Response formatting: answer
- Response formatting → Streamlit app: rendered response
- Streamlit app → Attribute retrieval: attribute request
- Attribute retrieval → Vector store: retrieves evidence
- Attribute retrieval → Extraction engine: evidence
- Extraction engine → Regex extractor: deterministic strategy
- Extraction engine → Summary engine: summarization strategy
- Extraction engine → vLLM API: extraction prompt
- Extraction engine → Post-processor: raw attribute
- Post-processor → Streamlit app: normalized result
- Policy concepts → Policy chain: shared policy semantics
- Shared data types → Policy chain: shared types
- Shared data types → Extraction engine: shared types