Retrieval pipeline, database schema, intelligence system, synthesis cascade, and configuration reference.
data/raw/ (immutable)
└─ parsers.py (v4) → plain text per file
└─ chunking.py → 450-word sliding windows, 70-word overlap
└─ embeddings.py → vector per chunk (hash / ST / OpenAI)
└─ SQLite → raw_files, chunks, chunk_embeddings, jobs
└─ ChromaDB → vector index (data/chroma/)
Query (web UI → POST /api/ask)
└─ retrieval.py → EvidencePack (8 chunks)
└─ llm.py → grounded answer + confidence score
└─ wiki/outputs/analysis/ → saved draft markdown
chunking.py — sliding window, word-based:
max_words = 450, overlap_words = 70, step = 380 wordslen(text.split()) * 4 // 3TextChunk(index, text, token_estimate)retrieve_evidence(question, limit=8) returns an EvidencePack:
Step 1 — File name match
Tokenizes the question, scores all raw_files by name/path overlap. If strong hits exist, returns their chunks directly without going further.
Step 2 — Query decomposition For complex queries (≥14 words or comparison/relationship terms), calls the configured model to split into 2–4 sub-queries. Falls back to deterministic regex splitting if no model available.
Step 3 — Parallel search (per sub-query)
retrieve_from_chroma() — ChromaDB semantic searchretrieve_by_keyword() — exact keyword group matching across all chunks in SQLiteretrieve_from_sqlite() — cosine similarity against hash embeddings in chunk_embeddings, filtered by keywordStep 4 — Reciprocal Rank Fusion (k=60)
Merges all ranked lists; best score per chunk_id kept.
Step 5 — Rerank and filter Keyword coverage bonus + source path bonus applied. Chunks below 45% of top score are dropped. Optional trained reranker applied if configured.
Step 6 — Extension filter If the question mentions a file type (e.g. "in my PDFs"), restricts to those extensions.
synthesize_answer(question, chunks, style) — three-tier cascade:
data/models/cognix-micro-synthesis.json), used when COGNIX_SYNTHESIS_BACKEND=cognix-microdata/models/cognix-sft-adapter.json), used when COGNIX_SYNTHESIS_BACKEND=cognix-sft-adapterauth_failed, model_unavailable, quota_exhausted, rate_limited, missing_key)source: path, chunk: id) — always available, no key requireddb/schema.sql)| Table | Purpose |
|---|---|
raw_files | path, sha256, size, extension, source_type, sensitivity, status, parser_version |
extracted_documents | file_id FK, title, text_path, text_preview, word_count, extraction_method |
chunks | file_id, document_id, chunk_index, text, token_estimate, source_path, sensitivity |
chunk_embeddings | chunk_id PK, vector_json, model, dimensions, provider, embedding_source |
jobs | kind, status, message, total, completed, failed, timestamps |
ingest_errors | job_id, path, error_type, message |
outputs | title, path, type, status, query, answer_preview, sources_json, retrieval_json |
health_findings | severity, category, title, message, path, status |
usage_events | provider, task, source, estimated_cost |
user_preferences | single-row (id=1), username, theme, default_answer_style |
provider_settings | provider PK, enabled, api_key, model, last_status, last_checked_at |
background_services | name PK, enabled, interval_seconds, last_run_at, last_message |
db/schema_v2.py)| Table | Purpose |
|---|---|
claims | chunk_id FK, claim_text, claim_type, confidence, embedding_json, status |
concept_mentions | concept, normalized_concept, chunk_id FK, mention_count |
intelligence_findings | finding_type, severity, title, description, suggested_action, status |
graph_edges | source_concept, target_concept, relationship, weight, source_chunk_id FK |
confidence_scores | output_id FK, query, score, label, breakdown_json |
briefings | brief_date UNIQUE, title, path, summary, finding_counts_json, status |
intelligence_runs | run_type, status, chunks/claims/concepts/findings counts, error |
model_predictions / prediction_outcomes / training_examples | ML calibration data |
model_artifacts | name, base_model, artifact_type, path, status, metrics_json |
calibration_models | task, method, parameters_json, brier_score, log_loss |
extraction_artifacts | file_id FK, artifact_type, method, confidence, page counts |
Located at services/intelligence/. Triggered by POST /api/intelligence/run or nightly scheduler.
GapDetector — finds concepts with ≤1 evidence source or zero retrieval hits → gap findings
ContradictionDetector — compares claim embeddings for semantic conflict → contradiction / contradiction_candidate findings; optionally uses LLM for verification
StalenessDetector — flags files not updated in >90 days or chunks with no recent query hits
After detection, generate_intelligence_brief() writes a markdown briefing to wiki/_intelligence/ and stores it in briefings.
SQLite-backed via graph_edges. API endpoints:
GET /api/graph/concept/{slug} — concept node + 1-hop neighborsGET /api/graph/neighbors/{slug} — recursive neighbors up to depth 3 (via recursive CTE)Edges are created by the intelligence pipeline when claims reference related concepts.
All environment variables are prefixed COGNIX_:
| Variable | Default | Options |
|---|---|---|
COGNIX_LOCAL_EMBEDDING_BACKEND | hash | hash, sentence-transformers, neural |
COGNIX_SYNTHESIS_BACKEND | provider | provider, cognix-micro, cognix-sft-adapter |
COGNIX_RERANKER_BACKEND | deterministic | deterministic, pair, cross-encoder, local-cross-encoder |
COGNIX_NLI_BACKEND | heuristic | heuristic, pair, cross-encoder, transformer-lora |
COGNIX_VISION_BACKEND | local-ocr | local-ocr, openai-vision |
COGNIX_CLOUD_EMBEDDINGS_ENABLED | false | true / false |
COGNIX_INTELLIGENCE_RUN_HOUR | 2 | Hour (0–23) for nightly run |
COGNIX_DATA_DIR | data/ | Path override |
COGNIX_WIKI_DIR | wiki/ | Path override |
COGNIX_RAW_DIR | data/raw/ | Path override |
| Route | Method | Purpose |
|---|---|---|
/api/ask | POST | Retrieve + synthesize answer |
/api/ingest | POST | Run file ingest + compile source summaries |
/api/outputs | GET/PATCH | List and update draft outputs |
/api/health | GET/POST | Run health check, return findings + score |
/api/jobs | GET | Ingest job history + errors |
/api/files | GET | List raw_files rows |
/api/providers | GET/POST | List, save, test model providers |
/api/settings | GET/POST | Read/write user preferences |
/api/background | GET/POST | List/toggle background services |
/api/intelligence/run | POST | Trigger intelligence pass |
/api/intelligence/findings | GET | List open findings |
/api/contradictions | GET | List contradictions |
/api/gaps | GET | List knowledge gap findings |
/api/gaps/{concept}/compile | POST | Generate concept wiki page from gap |
/api/graph/neighbors/{slug} | GET | Recursive concept graph neighbors |
/status | GET | Health ping |