# sherawatkamal/personal_knowledge_operating_system architecture

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

- Interactive diagram: https://gitdiagram.com/sherawatkamal/personal_knowledge_operating_system
- Repository: https://github.com/sherawatkamal/personal_knowledge_operating_system

## Overview

pkos is a self-hosted personal knowledge system that syncs personal records, indexes them, and answers questions with citations. The main user workflow is CLI-driven: sync a configured source into normalized episode records, embed and index those records, then retrieve relevant chunks and generate an answer. The repository also contains an evaluation harness for comparing answer configurations. The graph includes only relationships supported by the excerpts, SOURCE INDEX references, or README; some subsystem internals are unsampled, so their links are omitted rather than inferred.

Main entry points: [`src/pkos/cli.py`](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/cli.py) (Command-line interface), [`src/pkos/eval/runner.py`](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/runner.py) (Evaluation runner), [`src/pkos/embed/index.py`](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/embed/index.py) (Chunk indexing), [`src/pkos/llm/registry.py`](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/registry.py) (LLM registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Source ingestion"]
  node_settings["Application settings<br/>[config.py]"]
  node_granola["Granola connector<br/>[granola.py]"]
  node_sync["Source sync<br/>[sync.py]"]
  node_episode_model["Episode model<br/>[model.py]"]
  node_normalization["Episode normalization<br/>[normalize.py]"]
  node_episode_store["Episode persistence<br/>[store.py]"]
end

subgraph group_index["Search index"]
  node_chunking["Chunking<br/>[chunker.py]"]
  node_embedding["Local embeddings<br/>[fast.py]"]
  node_indexing["Chunk indexing<br/>[index.py]"]
  node_retrieval["Chunk retrieval<br/>[chunks.py]"]
end

subgraph group_answer["Answer generation"]
  node_answer_pipeline["Ask pipeline<br/>[pipeline.py]"]
  node_answer_stage["Answer and citations<br/>[stage.py]"]
end

subgraph group_models["Model services"]
  node_llm_registry["LLM registry<br/>[registry.py]"]
  node_llm_types["LLM interface<br/>[base.py]"]
  node_groq["Groq provider<br/>[groq.py]"]
  node_ollama["Ollama provider<br/>[ollama.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_questions["Evaluation questions<br/>[questions.py]"]
  node_eval_systems["Evaluation systems<br/>[systems.py]"]
  node_eval_runner["Evaluation runner<br/>[runner.py]"]
  node_scoring["Gold resolution and scoring<br/>[scoring.py]"]
  node_eval_reports["Evaluation reports<br/>[report.py]"]
end

node_user(("User"))
node_cli["Command-line interface<br/>[cli.py]"]
node_granola_api["Granola API"]
node_database[("PostgreSQL database")]
node_model_services["Configured model services"]

node_user -->|"runs commands"| node_cli
node_cli -->|"loads settings"| node_settings
node_cli -->|"runs sync"| node_sync
node_cli -->|"configures source"| node_granola
node_granola -->|"fetches notes"| node_granola_api
node_sync -->|"uses connector"| node_granola
node_granola -->|"converts notes"| node_normalization
node_normalization -->|"creates episodes"| node_episode_model
node_sync -->|"persists episodes"| node_episode_store
node_episode_store -->|"reads and writes"| node_database
node_cli -->|"runs indexing"| node_indexing
node_indexing -->|"chunks episodes"| node_chunking
node_indexing -->|"embeds text"| node_embedding
node_indexing -.->|"writes index"| node_database
node_cli -->|"asks question"| node_answer_pipeline
node_answer_pipeline -->|"searches chunks"| node_retrieval
node_retrieval -->|"embeds query"| node_embedding
node_retrieval -->|"queries chunks"| node_database
node_answer_pipeline -->|"passes retrieved hits"| node_answer_stage
node_answer_stage -->|"requests completion"| node_llm_registry
node_llm_registry -->|"implements interface"| node_llm_types
node_llm_registry -->|"selects provider"| node_groq
node_llm_registry -->|"selects provider"| node_ollama
node_groq -->|"calls provider"| node_model_services
node_ollama -.->|"calls service"| node_model_services
node_cli -->|"runs evaluation"| node_eval_runner
node_eval_runner -->|"uses question set"| node_questions
node_eval_runner -->|"runs systems"| node_eval_systems
node_eval_runner -->|"resolves and scores"| node_scoring
node_eval_systems -->|"uses ask pipeline"| node_answer_pipeline
node_scoring -->|"scores answers"| node_questions
node_eval_reports -->|"reads question data"| node_questions
node_eval_reports -->|"reads run results"| node_eval_runner
node_eval_reports -->|"reads score data"| node_scoring

click node_cli "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/cli.py"
click node_settings "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/config.py"
click node_granola "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/connectors/granola.py"
click node_sync "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/sync.py"
click node_episode_model "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/episodes/model.py"
click node_normalization "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/episodes/normalize.py"
click node_episode_store "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/episodes/store.py"
click node_chunking "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/embed/chunker.py"
click node_embedding "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/embed/fast.py"
click node_indexing "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/embed/index.py"
click node_retrieval "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/retrieve/chunks.py"
click node_answer_pipeline "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/answer/pipeline.py"
click node_answer_stage "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/answer/stage.py"
click node_llm_registry "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/registry.py"
click node_llm_types "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/base.py"
click node_groq "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/groq.py"
click node_ollama "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/ollama.py"
click node_questions "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/questions.py"
click node_eval_systems "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/systems.py"
click node_eval_runner "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/runner.py"
click node_scoring "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/scoring.py"
click node_eval_reports "https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/report.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_settings,node_granola,node_sync,node_episode_model,node_normalization,node_episode_store,node_user toneBlue
class node_chunking,node_embedding,node_indexing,node_retrieval,node_database toneAmber
class node_answer_pipeline,node_answer_stage,node_granola_api toneMint
class node_llm_registry,node_llm_types,node_groq,node_ollama toneRose
class node_questions,node_eval_systems,node_eval_runner,node_scoring,node_eval_reports,node_model_services toneIndigo
class node_cli toneTeal
```

## Components

### Source ingestion

- [Application settings](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/config.py): `src/pkos/config.py`
- [Granola connector](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/connectors/granola.py): `src/pkos/connectors/granola.py`
- [Source sync](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/sync.py): `src/pkos/sync.py`
- [Episode model](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/episodes/model.py): `src/pkos/episodes/model.py`
- [Episode normalization](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/episodes/normalize.py): `src/pkos/episodes/normalize.py`
- [Episode persistence](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/episodes/store.py): `src/pkos/episodes/store.py`

### Search index

- [Chunking](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/embed/chunker.py): `src/pkos/embed/chunker.py`
- [Local embeddings](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/embed/fast.py): `src/pkos/embed/fast.py`
- [Chunk indexing](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/embed/index.py): `src/pkos/embed/index.py`
- [Chunk retrieval](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/retrieve/chunks.py): `src/pkos/retrieve/chunks.py`

### Answer generation

- [Ask pipeline](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/answer/pipeline.py): `src/pkos/answer/pipeline.py`
- [Answer and citations](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/answer/stage.py): `src/pkos/answer/stage.py`

### Model services

- [LLM registry](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/registry.py): `src/pkos/llm/registry.py`
- [LLM interface](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/base.py): `src/pkos/llm/base.py`
- [Groq provider](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/groq.py): `src/pkos/llm/groq.py`
- [Ollama provider](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/llm/ollama.py): `src/pkos/llm/ollama.py`

### Evaluation

- [Evaluation questions](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/questions.py): `src/pkos/eval/questions.py`
- [Evaluation systems](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/systems.py): `src/pkos/eval/systems.py`
- [Evaluation runner](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/runner.py): `src/pkos/eval/runner.py`
- [Gold resolution and scoring](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/scoring.py): `src/pkos/eval/scoring.py`
- [Evaluation reports](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/eval/report.py): `src/pkos/eval/report.py`

### Other components

- **User**
- [Command-line interface](https://github.com/sherawatkamal/personal_knowledge_operating_system/blob/main/src/pkos/cli.py): `src/pkos/cli.py`
- **Granola API**
- **PostgreSQL database**
- **Configured model services**

## Connections

- User → Command-line interface: runs commands (evidence: `src/pkos/cli.py`)
- Command-line interface → Application settings: loads settings (evidence: `src/pkos/cli.py`)
- Command-line interface → Source sync: runs sync (evidence: `src/pkos/cli.py`)
- Command-line interface → Granola connector: configures source (evidence: `src/pkos/cli.py`)
- Granola connector → Granola API: fetches notes (evidence: `src/pkos/connectors/granola.py`)
- Source sync → Granola connector: uses connector (evidence: `src/pkos/sync.py`)
- Granola connector → Episode normalization: converts notes (evidence: `src/pkos/connectors/granola.py`)
- Episode normalization → Episode model: creates episodes (evidence: `src/pkos/episodes/normalize.py`)
- Source sync → Episode persistence: persists episodes (evidence: `src/pkos/sync.py`)
- Episode persistence → PostgreSQL database: reads and writes (evidence: `src/pkos/episodes/store.py`)
- Command-line interface → Chunk indexing: runs indexing (evidence: `src/pkos/cli.py`)
- Chunk indexing → Chunking: chunks episodes (evidence: `src/pkos/embed/index.py`)
- Chunk indexing → Local embeddings: embeds text (evidence: `src/pkos/embed/index.py`)
- Chunk indexing → PostgreSQL database: writes index
- Command-line interface → Ask pipeline: asks question (evidence: `src/pkos/cli.py`)
- Ask pipeline → Chunk retrieval: searches chunks (evidence: `src/pkos/answer/pipeline.py`)
- Chunk retrieval → Local embeddings: embeds query (evidence: `src/pkos/retrieve/chunks.py`)
- Chunk retrieval → PostgreSQL database: queries chunks (evidence: `src/pkos/retrieve/chunks.py`)
- Ask pipeline → Answer and citations: passes retrieved hits (evidence: `src/pkos/answer/pipeline.py`)
- Answer and citations → LLM registry: requests completion (evidence: `src/pkos/answer/stage.py`)
- LLM registry → LLM interface: implements interface (evidence: `src/pkos/llm/registry.py`)
- LLM registry → Groq provider: selects provider (evidence: `src/pkos/llm/registry.py`)
- LLM registry → Ollama provider: selects provider (evidence: `src/pkos/llm/registry.py`)
- Groq provider → Configured model services: calls provider (evidence: `src/pkos/llm/groq.py`)
- Ollama provider → Configured model services: calls service
- Command-line interface → Evaluation runner: runs evaluation (evidence: `src/pkos/cli.py`)
- Evaluation runner → Evaluation questions: uses question set (evidence: `src/pkos/eval/runner.py`)
- Evaluation runner → Evaluation systems: runs systems (evidence: `src/pkos/eval/runner.py`)
- Evaluation runner → Gold resolution and scoring: resolves and scores (evidence: `src/pkos/eval/runner.py`)
- Evaluation systems → Ask pipeline: uses ask pipeline (evidence: `src/pkos/eval/systems.py`)
- Gold resolution and scoring → Evaluation questions: scores answers (evidence: `src/pkos/eval/scoring.py`)
- Evaluation reports → Evaluation questions: reads question data (evidence: `src/pkos/eval/report.py`)
- Evaluation reports → Evaluation runner: reads run results (evidence: `src/pkos/eval/report.py`)
- Evaluation reports → Gold resolution and scoring: reads score data (evidence: `src/pkos/eval/report.py`)
