Memory
IntelligentRAG — Pattern Adoption from kaig, surrealfs, surrealql-language-server ## What Was Done Implemented 7 phases of pattern adoption into IntelligentRAG MCP server: ### Phase 1: SURQL Template System - Created `src/db/surql-templates.ts` with inlined SURQL templates - Templates: vector_search, bm25_search, hybrid_search, graph_query_in, graph_siblings, recursive_graph, define_relation, create_index_hnsw, flow - Added `executeTemplate()` method to SurrealClient for template-based queries - Note: wrangler doesn't support ?raw imports, so templates are inlined as strings ### Phase 2: Graph Traversal Engine - Created `src/engine/graph-traversal.ts` - Functions: `graphQueryIn()`, `graphSiblings()`, `recursiveGraphQuery()` - Inbound traversal with optional cosine similarity - Sibling discovery via shared relations - N-level recursive traversal using @.{n} operator ### Phase 3: Vector Search Improvements - Updated `src/engine/search.ts` to use SURQL templates - Added `threshold` (0-1) and `effort` (1-100, HNSW tuning) params - Default effort=40 (good balance of speed/recall) - Falls back to fn::search if template fails ### Phase 4: Query Validation - Created `src/engine/query-validator.ts` - Tiered validation (Option C): - BLOCK: SHELL, file::, http:: (always dangerous) - WARN: REMOVE, SLEEP, REBUILD, KILL, LIVE, duration:: (context-dependent) - ALLOW: everything else - Integrated into `query` tool ### Phase 5: Path-based Addressing - Added `path` field + unique index to document table in graph-schema.ts - Updated `ingestDocument()` and `ingestUrl()` to accept optional `path` param - Default paths: `/uploads/{filename}` for uploads, URL pathname for URLs - Added `resolve_path` MCP tool ### Phase 6: Reactive Flow Table - Created `src/engine/flow-engine.ts` - Functions: `registerFlow()`, `checkFlows()`, `markProcessed()`, `deleteFlow()` - Tracks dependencies for cascading re-processing - Added `register_flow` and `check_flows` MCP tools ### Phase 7: New MCP Tools (9 new tools) - `graph_query_in` — Inbound traversal with optional similarity - `graph_siblings` — Sibling discovery via shared relations - `recursive_graph` — N-level deep traversal - `resolve_path` — Look up document by path - `validate_query` — Check if SurrealQL is safe - `vector_search` — Direct vector search with tuning - `graph_stats` — Entity relationship density - `register_flow` — Register flow entry - `check_flows` — Check for pending re-processing ## Key Decisions - Query validation: Tiered (Option C) — block dangerous, warn on rest - HNSW effort: Default 40, exposed to LLM as param - Path addressing: LLM assigns paths during ingestion - Recursive depth: Default 5 ## Files Created/Modified - Created: src/db/surql-templates.ts - Created: src/engine/graph-traversal.ts - Created: src/engine/query-validator.ts - Created: src/engine/flow-engine.ts - Created: src/db/surql/*.surql (9 template files) - Modified: src/db/surrealdb-client.ts (executeTemplate method) - Modified: src/db/graph-schema.ts (path field + index) - Modified: src/engine/search.ts (template-based, threshold, effort) - Modified: src/engine/ingest.ts (path param) - Modified: src/server.ts (9 new tools, query validation) ## Deployment - Deployed: https://intelligent-rag.mike-c79.workers.dev - Version: e97b5b67-a09a-4c8e-b929-d2193cd2f387 - All tools tested and working
Tags: intelligentrag, surrealdb, mcp, kaig, surrealfs, architecture, project:intelligentrag, kind:episodic, status:canonical — Source: claude — 2026-07-18 14:48:51 UTC