# vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss architecture

> Architecture diagram of the GitHub repository vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss
- Repository: https://github.com/vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss

## Overview

##### Project type and purpose
- This is a full‑stack Python application providing a Generative AI–powered legal assistant.
- Key features:
- Document ingestion into a vector database (FAISS)
- Retrieval‑augmented generation using DeepSeek R1 and Ollama
- A simple web UI built with Streamlit (or Gradio)
- External API integrations (GROQ, ElevenLabs)

##### File structure
- No explicit frontend/backend folders; the codebase is a single Python package.
- Core modules:
- GenAILawyerUI.py – the Streamlit/Gradio UI entry point
- learnDocument_vector_database.py – document ingestion & FAISS setup
- laywerResponse_rag_pipeline.py – RAG orchestration (retrieval + LLM call)
- prompt.py – prompt templates and formatting logic
- Configuration:
- .env file (GROQ_API_KEY)
- requirements.txt (Python dependencies)

##### Extract insights from the README
- UI screenshots show two main flows: Document Review & Legal Analysis.
- Stack: DeepSeek R1, Ollama, FAISS, GROQ, Streamlit
- Run command discrepancy (“gradio_app.py” vs. GenAILawyerUI.py) implies the UI script
handles both Gradio and Streamlit under the same module.

##### Main components
a. UI Layer
- Streamlit (GenAILawyerUI.py)
- User flows:
- Upload documents
- Enter legal queries
b. Ingestion Layer
- learnDocument_vector_database.py
- FAISS vector store
- Storage of document embeddings
c. Retrieval & Generation Layer
- laywerResponse_rag_pipeline.py
- prompt.py for template management
- RAG flow: query → retrieve top‑k vectors → build prompt → call LLM
d. External Services
- DeepSeek R1 (local or remote model)
- Ollama (local LLM runtime)
- GROQ API (for embeddings or scoring)
- ElevenLabs (optional TTS if used)
e. Configuration & Secrets
- .env (GROQ_API_KEY)

##### Relationships and data flows
1. User uploads document → UI
2. UI invokes ingestion module → embeddings via FAISS & GROQ
3. User submits query → UI calls RAG pipeline
4. RAG pipeline retrieves similar embeddings from FAISS
5. Retrieved chunks + user query → prompt.py assembles prompt
6. Prompt sent to DeepSeek R1 or Ollama → model generates answer
7. Answer returned to UI → displayed to user
8. (Optional) Answer sent to ElevenLabs for TTS

##### Architectural patterns & principles
- Separation of concerns: UI vs. ingestion vs. retrieval/generation
- Modular design: each Python script encapsulates one responsibility
- Externalize configuration (.env)
- RAG pattern for combining vector retrieval with LLM inference

## Diagram (Mermaid)

```mermaid
flowchart TD
    UI["UI (GenAILawyerUI.py)"]:::ui
    Ingest["Ingestion Service<br/>(learnDocument_vector_database.py)"]:::core
    FAISS[(FAISS Vector DB)]:::datastore
    RAG["RAG Service<br/>(laywerResponse_rag_pipeline.py)"]:::core
    Prompt["Prompt Manager<br/>(prompt.py)"]:::core
    extDS1[/"DeepSeek R1"/]:::external
    extDS2[/"Ollama"/]:::external
    extDS3[/"GROQ API"/]:::external
    extDS4[/"ElevenLabs"/]:::external
    Config["requirements.txt"]:::core

    UI -->|"Upload documents"| Ingest
    Ingest -->|"Calls GROQ API"| extDS3
    extDS3 -->|"Return embeddings"| Ingest
    Ingest -->|"Store embeddings"| FAISS

    UI -->|"Submit query"| RAG
    RAG -->|"Retrieve embeddings"| FAISS
    RAG -->|"Use Prompt Manager"| Prompt
    Prompt -->|"Formatted prompt"| RAG

    RAG -->|"Call DeepSeek R1"| extDS1
    extDS1 -->|"Generated text"| RAG
    RAG -->|"Call Ollama"| extDS2
    extDS2 -->|"Generated text"| RAG

    RAG -->|"Response"| UI
    RAG -->|"Send to TTS"| extDS4
    extDS4 -->|"Audio"| UI

    Config -.-> UI

    click UI "https://github.com/vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss/blob/master/GenAILawyerUI.py"
    click Ingest "https://github.com/vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss/blob/master/learnDocument_vector_database.py"
    click RAG "https://github.com/vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss/blob/master/laywerResponse_rag_pipeline.py"
    click Prompt "https://github.com/vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss/blob/master/prompt.py"
    click Config "https://github.com/vaibhavdhingani/genai_personal_legal_assistant_deepkeekr1_ollama_faiss/blob/master/requirements.txt"

    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef core fill:#DFF7E3,stroke:#2E8B57,color:#2E8B57;
    classDef external fill:#FFE8CC,stroke:#FF8C00,color:#FF8C00;
    classDef datastore fill:#F3E6FF,stroke:#8A2BE2,color:#8A2BE2;
```
