Skip to main content
Glama
README.md
# ⚑ Knowledge Master

**Your codebase's memory.** A local knowledge graph that gives AI agents real understanding of your architecture β€” not just text search.

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
![Status: Stable](https://img.shields.io/badge/Status-Stable-green)
![Python 3.11+](https://img.shields.io/badge/Python-3.11+-blue)

---

## Why

Every time you start a new AI chat, it forgets everything. You re-explain your architecture, conventions, dependencies. Knowledge Master gives your AI **permanent, structured memory** about your entire system.

Unlike flat RAG tools that return "chunks about X", Knowledge Master builds a **graph** β€” so it can answer "what breaks if I change X?" by traversing actual relationships.

## What it does

- πŸ” **Semantic search** across all your code, docs, and configs
- πŸ•ΈοΈ **Knowledge graph** β€” relationships between services, people, repos, technologies
- πŸ’₯ **Blast radius** β€” "what depends on this service/file/technology?"
- πŸ“ **Convention enforcement** β€” detects and enforces your team's patterns
- πŸ€– **MCP server** β€” plugs directly into AI agents (Kiro, Claude, Cursor)
- πŸ–₯️ **Web UI** β€” search, browse, visualize your knowledge graph
- πŸ”’ **Local-first** β€” nothing leaves your machine

## Prerequisites

| Dependency | macOS | Ubuntu/Debian | Windows |
|---|---|---|---|
| **Docker** | `brew install colima && colima start` or Docker Desktop | `sudo apt install docker.io docker-compose-plugin` | [Docker Desktop](https://docker.com/products/docker-desktop/) |
| **Ollama** | `brew install ollama && ollama serve` | `curl -fsSL https://ollama.com/install.sh \| sh` | [Ollama installer](https://ollama.com/download) |
| **Python 3.11+** | `brew install python@3.12` | `sudo apt install python3.12 python3.12-venv` | [python.org](https://python.org/downloads/) |

## Quick Start

```bash
# Install (pick one)
pipx install knowledge-master         # recommended (isolated, clean)
pip install knowledge-master           # or with pip

# Or via Homebrew (macOS)
brew install pipx && pipx install knowledge-master

# Or from source
git clone https://github.com/subzone/knowledge-master.git
cd knowledge-master
python3 -m venv .venv && source .venv/bin/activate
pip install -e .

# One command setup
km start

# Index your first repo
km index ~/path/to/your/project

# Search
km search "authentication flow"

# Check blast radius
km blast-radius postgres

# Start web UI with graph visualization
km serve
```

**Requirements:** Docker, Ollama, Python 3.11+

## Features

### Semantic Search with Graph Context
```bash
$ km search "how does auth work"
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Score  β”‚ Source               β”‚ Context             β”‚ Preview              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0.847  β”‚ src/auth/service.py  β”‚ repo:myapp, by:Alex β”‚ JWT token validat... β”‚
β”‚ 0.791  β”‚ docs/auth.md         β”‚ repo:myapp          β”‚ Authentication f...  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Blast Radius Analysis
```bash
$ km blast-radius auth-service
πŸ’₯ Blast radius: auth-service
β”œβ”€β”€ βš™οΈ user-service (Service, via DEPENDS_ON)
β”œβ”€β”€ βš™οΈ payment-service (Service, via DEPENDS_ON)
β”œβ”€β”€ πŸ“¦ frontend (Repo, via USES_SERVICE)
└── πŸ‘€ Alex (Person, via AUTHORED)

4 entities affected
```

### Convention Enforcement
```bash
$ km check-conventions ~/my-project
  βœ“ src/ directory (structure)
  βœ“ separate test directory (testing)
  βœ— snake_case files (file-naming)
  βœ“ Repository pattern (design-pattern)

1 convention(s) violated
```

### Web UI & Graph Visualization

```bash
$ km serve
Knowledge Master UI β†’ http://127.0.0.1:9999
```

Interactive force-directed graph showing your entire knowledge topology:
- πŸ“¦ Repos (blue) β†’ πŸ”§ Technologies (red)
- βš™οΈ Services (orange) β†’ Dependencies
- πŸ‘€ People β†’ Authorship
- πŸ“ Conventions (purple)

### MCP Integration (AI Agents)

Add to your Kiro/Claude agent config:

```json
{
  "mcpServers": {
    "knowledge": {
      "command": "km-server"
    }
  }
}
```

Your AI agent gets these tools:
- `search` β€” semantic search with graph context
- `blast_radius` β€” dependency analysis
- `check_conventions` β€” verify code follows team patterns
- `index_repo` β€” add new repos to the knowledge base

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  Your AI Agent                    β”‚
β”‚              (Kiro / Claude / Cursor)             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚ MCP Protocol
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Knowledge Master                    β”‚
β”‚                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Search  β”‚  β”‚Blast Radiusβ”‚  β”‚ Conventionsβ”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚       β”‚               β”‚               β”‚         β”‚
β”‚  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚            FalkorDB (Graph + Vector)       β”‚  β”‚
β”‚  β”‚                                           β”‚  β”‚
β”‚  β”‚  [Repo]──USES_TECH──▢[Tech]              β”‚  β”‚
β”‚  β”‚    β”‚                                      β”‚  β”‚
β”‚  β”‚    β”œβ”€β”€DEFINES_SERVICE──▢[Service]         β”‚  β”‚
β”‚  β”‚    β”‚                      β”‚               β”‚  β”‚
β”‚  β”‚    β”œβ”€β”€FOLLOWS──▢[Convention]              β”‚  β”‚
β”‚  β”‚    β”‚                                      β”‚  β”‚
β”‚  β”‚  [Person]──AUTHORED──▢[Document]          β”‚  β”‚
β”‚  β”‚                          β”‚                β”‚  β”‚
β”‚  β”‚                    [Chunk + Embedding]     β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚         Ollama (nomic-embed-text)          β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Commands

| Command | Description |
|---|---|
| `km start` | Boot Docker + pull embedding model |
| `km stop` | Stop containers |
| `km index <path>` | Index a git repo or docs directory |
| `km search <query>` | Semantic search with re-ranking |
| `km blast-radius <target>` | Multi-layer dependency analysis |
| `km safe-to-change <target>` | Risk assessment (safe/risky/dangerous) |
| `km who-owns <file>` | File ownership (git blame, recency-weighted) |
| `km check-conventions <path>` | Verify code follows detected patterns |
| `km connect <source>` | Pull from external MCP (email, Slack) |
| `km setup <tool>` | Auto-configure MCP for AI tools |
| `km watch <path>` | File watcher with auto re-index |
| `km upgrade` | Migrate graph schema |
| `km prune` | Remove stale/orphaned data |
| `km changelog` | Generate CHANGELOG.md |
| `km list` | Show indexed repos, techs, stats |
| `km remove <name>` | Remove a source |
| `km serve` | Start web UI at http://127.0.0.1:9999 |
| `km status` | Check system health |

## What gets extracted automatically

When you index a repo, Knowledge Master detects:

| Category | Examples |
|---|---|
| **Tech stack** | Languages, frameworks, packages from dependency files |
| **Services** | From docker-compose.yml and K8s manifests |
| **Dependencies** | Service-to-service relationships |
| **Conventions** | File naming (snake_case/kebab-case), folder structure, design patterns |
| **People** | Git commit authors and file ownership |
| **Code structure** | Functions, classes, chunked by AST-aware boundaries |

## Feature Status

| Feature | Status | Notes |
|---|---|---|
| Semantic search + re-ranking | βœ… Stable | Two-pass retrieval with confidence scoring |
| Knowledge graph (FalkorDB) | βœ… Stable | Nodes, edges, vector index, schema versioning |
| CLI (14 commands) | βœ… Stable | start, index, search, blast-radius, safe-to-change, who-owns, etc. |
| MCP server (8 tools) | βœ… Stable | search, blast_radius, safe_to_change, who_owns, check_conventions, index, status |
| REST API | βœ… Stable | /api/v1/ with OpenAPI docs |
| Web UI + graph viz | βœ… Stable | htmx + D3, search, file browser, graph |
| Git repo indexing | βœ… Stable | Parses code, extracts authors, detects tech stack |
| Multi-language static analysis | βœ… Stable | Python (ast), TypeScript, Go, Rust (tree-sitter) |
| Blast radius (multi-layer) | βœ… Stable | Imports β†’ services β†’ people, confidence levels |
| `safe-to-change` risk assessment | βœ… Stable | Blast radius + test coverage = risk score |
| Git blame ownership | βœ… Stable | Recency-weighted (3x/2x/1x) |
| Schema migrations | βœ… Stable | Auto-migrate, km upgrade |
| Deduplication | βœ… Stable | Content hash, skips unchanged |
| Convention detection | ⚑ Basic | Folder structure + file naming patterns |
| Email connector (ms-365) | πŸ§ͺ Experimental | Works, requires external MCP setup |
| `km watch` | πŸ§ͺ Experimental | Polling-based, may change |

**Legend:** βœ… Stable β€” ⚑ Basic (works, limited scope) β€” πŸ§ͺ Experimental (may change)

## Comparison

| Feature | Knowledge Master | Generic RAG | GitHub Copilot | Glean |
|---|---|---|---|---|
| Graph relationships | βœ… | ❌ | ❌ | Partial |
| Blast radius analysis | βœ… | ❌ | ❌ | ❌ |
| Convention enforcement | βœ… | ❌ | ❌ | ❌ |
| Local-first (no cloud) | βœ… | βœ… | ❌ | ❌ |
| MCP integration | βœ… | ❌ | ❌ | ❌ |
| Multi-repo intelligence | βœ… | Partial | ❌ | βœ… |
| Cost | Free | Free | $19/mo | $15-30/mo |

## Development

```bash
# Run tests
pytest

# Lint
ruff check knowledge_master/

# Run MCP server directly
python -m knowledge_master.server

# Run CLI directly
python -m knowledge_master.cli status
```

## Security

Knowledge Master runs **entirely on your machine**. No data leaves localhost.

- All ports bound to `127.0.0.1` (not accessible from LAN)
- Ollama runs locally β€” no cloud API calls
- MCP server uses stdio (no network exposure)
- Optional API key auth for REST endpoints

```bash
# Enable API key auth
export KM_API_KEY=$(openssl rand -hex 32)
km serve
```

See [SECURITY.md](SECURITY.md) for full security model, risks, and hardening guide.

## Troubleshooting

| Issue | Fix |
|---|---|
| `km start` fails with "Docker not running" | Start Docker: `colima start` (macOS) or `sudo systemctl start docker` (Linux) |
| `km start` fails with "Ollama not found" | Install Ollama from https://ollama.com and run `ollama serve` |
| `km index` is slow | First run downloads the embedding model (~274MB). Subsequent runs are fast. |
| Web UI shows "Connection refused" | Make sure containers are running: `km start` |
| Search returns poor results | Index more content. Quality improves with more context in the graph. |
| Port 9999 already in use | Use `km serve --port 8888` |

## License

MIT

TDQS

A3.6/5.0

Scored across 8 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: indexing, searching, impact analysis, ownership, conventions checking. Even similar tools like blast_radius and safe_to_change are differentiated by depth of analysis.

Naming Consistency4/5

Tools use snake_case consistently. Most follow verb_noun pattern (index_directory, check_conventions), but some are noun-based (blast_radius, safe_to_change). Still predictable and readable.

Tool Count5/5

8 tools is well-scoped for a knowledge management server. Each tool covers a core function without redundancy or bloat.

Completeness4/5

Covers indexing, search, impact analysis, conventions checking, and ownership. Missing delete or update operations for indexed data, but core read-oriented workflows are complete.

Maintenance

ActivityInactive
ResponsivenessNo issues