# tuanduy35399/chat_service_nckh architecture

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

- Interactive diagram: https://gitdiagram.com/tuanduy35399/chat_service_nckh
- Repository: https://github.com/tuanduy35399/chat_service_nckh

## Overview

Mai Vang Chat Service is a Vietnamese plant-disease assistant: users submit a question (optionally with conversation history or image-detection results), the API prepares the request, and retrieval-augmented generation returns an answer. The main knowledge workflow loads Markdown files, chunks and embeds them into a persistent Chroma store; chat retrieves context and calls Google Gemini. A separate indexing script in rag_indexing describes another Markdown-to-Chroma approach, but its excerpt contains an undefined splitter, so its runtime status is uncertain. Links below are limited to documented or excerpted relationships.

Main entry points: [`google_model/rag.py`](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/rag.py) (RAG answering), [`google_model/ingest.py`](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/ingest.py) (Text chunking), [`rag_indexing/chunking.py`](https://github.com/tuanduy35399/chat_service_nckh/blob/main/rag_indexing/chunking.py) (Alternate indexer), [`google_model/main.py`](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/main.py) (Image enrichment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Chat service"]
  node_api["Chat API<br/>[main.py]"]
  node_image_enrichment["Image enrichment<br/>[main.py]"]
end

subgraph group_knowledge["Knowledge retrieval"]
  node_rag["RAG answering<br/>[rag.py]"]
  node_retriever["Top-3 retriever<br/>[rag.py]"]
  node_vector_store[("Chroma store")]
end

subgraph group_indexing["Knowledge indexing"]
  node_markdown["Markdown knowledge"]
  node_ingest["Document loading<br/>[ingest.py]"]
  node_ingest_chunks["Text chunking<br/>[ingest.py]"]
  node_embedding["Google embeddings<br/>[ingest.py]"]
  node_legacy_indexer["Alternate indexer<br/>[chunking.py]"]
  node_sentence_embedding["Sentence embeddings<br/>[chunking.py]"]
  node_legacy_store[("Chroma collection<br/>[chunking.py]")]
end

node_user(("User"))
node_detections["YOLO detections"]
node_gemini["Gemini chat model"]

node_user -->|"submits question"| node_api
node_user -->|"provides request"| node_image_enrichment
node_detections -->|"supplies results"| node_image_enrichment
node_image_enrichment -->|"calls ask"| node_rag
node_api -->|"calls ask"| node_rag
node_rag -->|"invokes retrieval"| node_retriever
node_retriever -->|"retrieves documents"| node_vector_store
node_rag -->|"invokes model"| node_gemini
node_markdown -->|"loads files"| node_ingest
node_ingest -->|"splits documents"| node_ingest_chunks
node_ingest_chunks -->|"embeds chunks"| node_embedding
node_ingest_chunks -->|"indexes chunks"| node_vector_store
node_markdown -->|"reads Markdown"| node_legacy_indexer
node_legacy_indexer -->|"encodes chunks"| node_sentence_embedding
node_legacy_indexer -->|"adds chunks"| node_legacy_store

click node_api "https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/main.py"
click node_image_enrichment "https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/main.py"
click node_rag "https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/rag.py"
click node_retriever "https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/rag.py"
click node_vector_store "https://github.com/tuanduy35399/chat_service_nckh/tree/main/google_model/vector_db"
click node_markdown "https://github.com/tuanduy35399/chat_service_nckh/tree/main/data"
click node_ingest "https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/ingest.py"
click node_ingest_chunks "https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/ingest.py"
click node_embedding "https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/ingest.py"
click node_legacy_indexer "https://github.com/tuanduy35399/chat_service_nckh/blob/main/rag_indexing/chunking.py"
click node_sentence_embedding "https://github.com/tuanduy35399/chat_service_nckh/blob/main/rag_indexing/chunking.py"
click node_legacy_store "https://github.com/tuanduy35399/chat_service_nckh/blob/main/rag_indexing/chunking.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_image_enrichment,node_user toneBlue
class node_rag,node_retriever,node_vector_store toneAmber
class node_markdown,node_ingest,node_ingest_chunks,node_embedding,node_legacy_indexer,node_sentence_embedding,node_legacy_store toneMint
class node_detections,node_gemini toneIndigo
```

## Components

### Chat service

- [Chat API](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/main.py): `google_model/main.py`
- [Image enrichment](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/main.py): `google_model/main.py`

### Knowledge retrieval

- [RAG answering](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/rag.py): `google_model/rag.py`
- [Top-3 retriever](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/rag.py): `google_model/rag.py`
- [Chroma store](https://github.com/tuanduy35399/chat_service_nckh/tree/main/google_model/vector_db): `google_model/vector_db`

### Knowledge indexing

- [Markdown knowledge](https://github.com/tuanduy35399/chat_service_nckh/tree/main/data): `data`
- [Document loading](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/ingest.py): `google_model/ingest.py`
- [Text chunking](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/ingest.py): `google_model/ingest.py`
- [Google embeddings](https://github.com/tuanduy35399/chat_service_nckh/blob/main/google_model/ingest.py): `google_model/ingest.py`
- [Alternate indexer](https://github.com/tuanduy35399/chat_service_nckh/blob/main/rag_indexing/chunking.py): `rag_indexing/chunking.py`
- [Sentence embeddings](https://github.com/tuanduy35399/chat_service_nckh/blob/main/rag_indexing/chunking.py): `rag_indexing/chunking.py`
- [Chroma collection](https://github.com/tuanduy35399/chat_service_nckh/blob/main/rag_indexing/chunking.py): `rag_indexing/chunking.py`

### Other components

- **User**
- **YOLO detections**
- **Gemini chat model**

## Connections

- User → Chat API: submits question (evidence: `google_model/main.py`)
- User → Image enrichment: provides request (evidence: `google_model/main.py`)
- YOLO detections → Image enrichment: supplies results (evidence: `google_model/main.py`)
- Image enrichment → RAG answering: calls ask (evidence: `google_model/main.py`)
- Chat API → RAG answering: calls ask (evidence: `google_model/main.py`)
- RAG answering → Top-3 retriever: invokes retrieval (evidence: `google_model/rag.py`)
- Top-3 retriever → Chroma store: retrieves documents (evidence: `google_model/rag.py`)
- RAG answering → Gemini chat model: invokes model (evidence: `google_model/rag.py`)
- Markdown knowledge → Document loading: loads files (evidence: `google_model/ingest.py`)
- Document loading → Text chunking: splits documents (evidence: `google_model/ingest.py`)
- Text chunking → Google embeddings: embeds chunks (evidence: `google_model/ingest.py`)
- Text chunking → Chroma store: indexes chunks (evidence: `google_model/ingest.py`)
- Markdown knowledge → Alternate indexer: reads Markdown (evidence: `rag_indexing/chunking.py`)
- Alternate indexer → Sentence embeddings: encodes chunks (evidence: `rag_indexing/chunking.py`)
- Alternate indexer → Chroma collection: adds chunks (evidence: `rag_indexing/chunking.py`)
