Chaos Cypher Cortex - Full-featured knowledge graph platform (processing center)
Project description
ChaosCypher Cortex
Full-featured knowledge graph backend API - Processing center
Cortex is the main backend API for ChaosCypher, providing comprehensive CRUD operations, workflow execution, document source processing, AI-powered chat, and knowledge graph management using Vertical Slice Architecture (VSA).
Features
- ๐ Knowledge Graph Management: Full CRUD for nodes, edges, and templates
- ๐ฌ AI Chat: Conversational interface with RAG and tool use
- ๐ Document Source Processing: Process PDFs, text files, CSVs into knowledge graphs
- ๐ Workflow Engine: Execute multi-step AI research workflows with triggers
- ๐ Search: FTS5 full-text + sqlite-vec vector search; multi-hop GraphRAG retrieval
- ๐ MCP Server: Expose graph operations as Model Context Protocol tools
- โ๏ธ Settings Management: Configure LLM providers, databases, and system settings
- ๐ Single-User Auth: nginx
auth_requestgates every API call (no admin/user split) - ๐๏ธ Multi-Database: Isolated workspaces with independent graphs
Architecture
Cortex is part of the ChaosCypher neural architecture:
- Core - Brain (business logic)
- Cortex - Processing center (full backend) ๐ You are here
- Neuron - Worker cells (background processing)
- Interface - Interaction layer (UI)
Vertical Slice Architecture (VSA)
Cortex uses VSA with self-contained feature slices. Each slice contains its
own routes, service logic, and Pydantic models. The authoritative list is the
set of directories under
packages/cortex/src/chaoscypher_cortex/features/:
packages/cortex/src/chaoscypher_cortex/
โโโ features/ # VSA slices (chats, sources, nodes, edges,
โ # templates, search, llm, queue, settings,
โ # settings_public, workflows, triggers, tools,
โ # dashboard, graph, graph_snapshot, mcp, lexicon,
โ # backup, export, quality, counts, health,
โ # diagnostics, logs, pause, upgrade, edition,
โ # databases, local_auth, admin_plugins)
โโโ shared/ # Shared infrastructure
โ โโโ api/ # Auth dependencies, error handling, pagination
โ โโโ database/ # Database session
โ โโโ llm/ # LLM factory
โ โโโ queue/ # Queue utilities
โโโ main.py # FastAPI application + router registration
Each feature slice contains:
models.py- Pydantic DTOs (Request/Response)repository.py- Data access layerservice.py- Business logicapi.py- REST endpoints + DI factory__init__.py- Barrel exports
Installation
# From source (workspace sync โ installs core + cortex + all dev tools)
uv sync --all-packages --extra dev
# Single-package mode (cortex + its core dep only)
uv sync --package chaoscypher-cortex
The repo uses uv workspaces (see pyproject.toml [tool.uv.workspace]); pip install -e is no longer the supported install path. Install uv via
the official installer
before running these commands.
Usage
Standalone
# Start Cortex server
cc-cortex start
# Custom host/port
cc-cortex start --host 0.0.0.0 --port 8080
# With environment variables
QUEUE_HOST=localhost QUEUE_PORT=6379 cc-cortex start
Docker
# Development
docker compose -f packages/docker/multi-container/docker-compose.dev.yml up cortex
# Production
docker run -p 8080:8080 -e QUEUE_HOST=valkey -e QUEUE_PORT=6379 chaoscypher-cortex
Programmatic
from chaoscypher_cortex.main import create_app
app = create_app()
# Run with uvicorn
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8080)
Configuration
Configure via environment variables or packages/docker/data/settings.yaml:
# Queue (Valkey)
QUEUE_HOST=localhost
QUEUE_PORT=6379
# Database
CHAOSCYPHER_DATA_DIR=~/.local/share/chaoscypher
CHAOSCYPHER_CONFIG_DIR=~/.config/chaoscypher
# Logging
LOG_LEVEL=INFO
USE_JSON_LOGGING=false
# LLM Provider
LLM_CHAT_PROVIDER=ollama
LLM_CHAT_MODEL=llama3.2
LLM_EMBEDDING_PROVIDER=ollama
LLM_EMBEDDING_MODEL=snowflake-arctic-embed2
# API Keys (if using cloud providers)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...
API Endpoints
Routes live under /api/v1/ and are gated by nginx auth_request (no
register/login flow inside Cortex). The full surface includes:
- Knowledge graph โ
/nodes,/edges,/templates,/graph - Sources โ
/sources(upload, list, extract, commit, citations, chunks).SourceResponseexposes user upload-time choices via the nestedupload_optionsobject (auto_analyze,enable_normalization,enable_vision,content_filtering,filtering_mode,extraction_depth,forced_domain), per-stage drop / merge counters viaquality_metrics(45 typed counters + companion fields likeloader_encoding_used), and search-index health viaquality_metrics.vector_indexing_status(pending/indexed/degraded/failed). New persisted upload settings must round-trip throughupload_options, never as siblings onSourceResponseโ seepackages/docs/docs/reference/api/sources.md. - Search โ
/search(FTS5, vector, hybrid, GraphRAG) - Chat โ
/chats,/chats/{id}/messages - Workflows โ
/workflows,/workflows/{id}/execute,/triggers,/tools - Settings โ
/settings,/settings/reset(plus scoped/settings/reset/{scope}variants) - Queue โ
/queue/tasks,/queue/status - Operations โ
/llm/instances,/databases,/exports,/backup - Diagnostics โ
/health,/diagnostics,/logs,/pause,/edition - MCP โ
/mcp/sse,/mcp/messages
The complete reference (request/response shapes, query params, error envelopes)
is in packages/docs/docs/reference/api/ and at the live OpenAPI page:
http://localhost:8080/docs (when running).
Development
Project Structure
packages/cortex/
โโโ src/chaoscypher_cortex/
โ โโโ features/ # VSA feature slices
โ โโโ shared/ # Shared infrastructure
โ โโโ main.py # FastAPI app
โโโ tests/ # Test suite
โโโ Dockerfile # Production image
โโโ Dockerfile.dev # Development image
โโโ pyproject.toml # Package configuration
Adding New Features
- Create directory:
features/{feature}/ - Define DTOs:
{feature}/models.py - Create repository:
{feature}/repository.py - Create service:
{feature}/service.py - Create API + factory:
{feature}/api.py - Export:
{feature}/__init__.py - Register router in
main.py
Example:
# features/my_feature/models.py
from pydantic import BaseModel
class MyFeatureRequest(BaseModel):
name: str
class MyFeatureResponse(BaseModel):
id: str
name: str
# features/my_feature/service.py
class MyFeatureService:
def create(self, data: dict) -> dict:
# Business logic
return {"id": "123", "name": data["name"]}
# features/my_feature/api.py
from fastapi import APIRouter, Depends
router = APIRouter(prefix="/api/v1/my-feature", tags=["My Feature"])
def get_service() -> MyFeatureService:
return MyFeatureService()
@router.post("/", response_model=MyFeatureResponse)
def create_item(
request: MyFeatureRequest,
service: Annotated[MyFeatureService, Depends(get_service)]
):
return service.create(request.model_dump())
Testing
# Run all tests
pytest
# Unit tests only
pytest -m unit
# Integration tests
pytest -m integration
# With coverage
pytest --cov=chaoscypher_cortex --cov-report=html
Hot-Reload Development
# Using watchdog
watchmedo auto-restart -d src -p '*.py' -- cc-cortex start
# Using Docker
docker compose -f packages/docker/multi-container/docker-compose.dev.yml up cortex
Dependencies
- Core:
chaoscypher-core- Business logic - FastAPI: Web framework
- SQLModel: Database ORM
- ARQ: Background task queue
- Structlog: Structured logging
- Pydantic: Data validation
License
AGPL-3.0 License - See LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chaoscypher_cortex-0.1.0.tar.gz.
File metadata
- Download URL: chaoscypher_cortex-0.1.0.tar.gz
- Upload date:
- Size: 268.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
410d787445794750401cedff32a7b847e767f3009fa5fe70124d015d6d950176
|
|
| MD5 |
539157ec4d1fa7c70227ef329d7b5e8c
|
|
| BLAKE2b-256 |
f8e56b444d42d04f15f5c0cc3cc891286882bb43fdd11eb2df694668cf0b3bae
|
File details
Details for the file chaoscypher_cortex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chaoscypher_cortex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 360.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecd2889b9738838a0e477fb187694ea77e61c897c888e9d467651c49eda3ff5f
|
|
| MD5 |
b9f15ae9e1a683198209813a03c71b72
|
|
| BLAKE2b-256 |
1b98e9b7148ac5fa4dc11c30c254f50905d6dae6618c6ac526fbdbade2ba2ec3
|