# rk936503/enterprise-knowledge-base-rag architecture

> Architecture diagram of the GitHub repository rk936503/enterprise-knowledge-base-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rk936503/enterprise-knowledge-base-rag
- Repository: https://github.com/rk936503/enterprise-knowledge-base-rag

## Overview

This repository is the early core of an API-based RAG knowledge base: users are meant to upload documents and query for grounded, cited answers. The source shows chunking, embedding-provider selection, answer generation, configuration, and database models/session setup, but no router implementation or retrieval code. Accordingly, the documented upload/query stages are represented, while their runtime wiring to these components is left unspecified.

Main entry points: [`app/embeddings.py`](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/embeddings.py) (Embedding service), [`app/config.py`](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/config.py) (Runtime settings), [`app/llm.py`](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/llm.py) (Grounded answer generation), [`app/chunking.py`](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/chunking.py) (Text chunking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflow"]
  node_api["Upload and query API"]
end

subgraph group_ingest["Document processing"]
  node_chunking["Text chunking<br/>[chunking.py]"]
  node_embeddings["Embedding service<br/>[embeddings.py]"]
end

subgraph group_answer["Answer generation"]
  node_retrieval["Relevant chunk retrieval"]
  node_generation["Grounded answer generation<br/>[llm.py]"]
end

subgraph group_data["Persistence and settings"]
  node_models["Document and query models<br/>[models.py]"]
  node_database["Database sessions<br/>[database.py]"]
  node_config["Runtime settings<br/>[config.py]"]
end

node_user(("API user"))
node_postgres[("PostgreSQL with pgvector")]
node_openai["OpenAI embeddings"]
node_localmodel["Local embedding model"]
node_anthropic["Anthropic Claude"]

node_user -->|"uploads and queries"| node_api
node_embeddings -->|"requests embeddings"| node_openai
node_embeddings -->|"encodes locally"| node_localmodel
node_generation -->|"requests generation"| node_anthropic
node_database -->|"creates engine"| node_postgres
node_models -->|"maps persisted records"| node_postgres
node_chunking -->|"reads settings"| node_config
node_embeddings -->|"reads settings"| node_config
node_generation -->|"reads settings"| node_config

click node_api "https://github.com/rk936503/enterprise-knowledge-base-rag/tree/main/app/routers"
click node_chunking "https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/chunking.py"
click node_embeddings "https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/embeddings.py"
click node_retrieval "https://github.com/rk936503/enterprise-knowledge-base-rag/tree/main/app"
click node_generation "https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/llm.py"
click node_models "https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/models.py"
click node_database "https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/database.py"
click node_config "https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/config.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_user toneBlue
class node_chunking,node_embeddings,node_postgres toneAmber
class node_retrieval,node_generation toneMint
class node_models,node_database,node_config toneRose
class node_openai,node_localmodel,node_anthropic toneIndigo
```

## Components

### API workflow

- [Upload and query API](https://github.com/rk936503/enterprise-knowledge-base-rag/tree/main/app/routers): `app/routers`

### Document processing

- [Text chunking](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/chunking.py): `app/chunking.py`
- [Embedding service](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/embeddings.py): `app/embeddings.py`

### Answer generation

- [Relevant chunk retrieval](https://github.com/rk936503/enterprise-knowledge-base-rag/tree/main/app): `app`
- [Grounded answer generation](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/llm.py): `app/llm.py`

### Persistence and settings

- [Document and query models](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/models.py): `app/models.py`
- [Database sessions](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/database.py): `app/database.py`
- [Runtime settings](https://github.com/rk936503/enterprise-knowledge-base-rag/blob/main/app/config.py): `app/config.py`

### Other components

- **API user**
- **PostgreSQL with pgvector**
- **OpenAI embeddings**
- **Local embedding model**
- **Anthropic Claude**

## Connections

- API user → Upload and query API: uploads and queries
- Embedding service → OpenAI embeddings: requests embeddings
- Embedding service → Local embedding model: encodes locally
- Grounded answer generation → Anthropic Claude: requests generation
- Database sessions → PostgreSQL with pgvector: creates engine
- Document and query models → PostgreSQL with pgvector: maps persisted records
- Text chunking → Runtime settings: reads settings
- Embedding service → Runtime settings: reads settings
- Grounded answer generation → Runtime settings: reads settings
