{"_id":"@context-router/llamaindex-adapter","name":"@context-router/llamaindex-adapter","dist-tags":{"latest":"0.5.0"},"versions":{"0.5.0":{"name":"@context-router/llamaindex-adapter","version":"0.5.0","description":"LlamaIndex adapter for Context Router - Vector search, semantic retrieval, and chat memory","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"},"./storage":{"import":"./dist/storage/index.js","types":"./dist/storage/index.d.ts"}},"license":"Apache-2.0","scripts":{"build":"rimraf dist && tsc","dev":"tsc --watch","test":"vitest run","prepack":"npm run build"},"keywords":["context-router","llamaindex","mcp","multi-agent","memory","vector-search"],"peerDependencies":{"@context-router/sdk":"^0.5.0","llamaindex":">=0.5.0"},"peerDependenciesMeta":{"llamaindex":{"optional":true}},"devDependencies":{"@context-router/sdk":"^0.5.0","@types/node":"^20.0.0","typescript":"^5.6.0","vitest":"^2.1.0"},"dependencies":{"uuid":"^10.0.0","zod":"^3.23.0"},"repository":{"type":"git","url":"git+https://github.com/mindlever-strategy/context-router.git","directory":"packages/llamaindex-adapter"},"homepage":"https://github.com/mindlever-strategy/context-router#readme","bugs":{"url":"https://github.com/mindlever-strategy/context-router/issues"},"engines":{"node":">=20"},"publishConfig":{"access":"public","provenance":true},"gitHead":"cf5dc2d8c2c7ab2b11027f6f9eae1727d388c069","_id":"@context-router/llamaindex-adapter@0.5.0","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-B5ZhHzG0n8/9wOWp6WaudqXX1JFFIBO1sX+pfuVVf2BIOE5HLDR0aTzmwPjmwk6fI2LlCaJn+SMIvV0aVl2jBg==","shasum":"54366a6f8cb620d1951f68cf121a3eeb27d3f430","tarball":"https://registry.npmjs.org/@context-router/llamaindex-adapter/-/llamaindex-adapter-0.5.0.tgz","fileCount":11,"unpackedSize":27006,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@context-router%2fllamaindex-adapter@0.5.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDbIXr8FZ27O0xUUBQECGhpLyKdmpY4EQDQNd1NjvW4hQIhANEz/IjiZ/LEtGBUzE2HHoWL3BaIhzqtel8La3L4eq/X"}]},"_npmUser":{"name":"harshitpanchal","email":"harshitpanchal.ai@gmail.com"},"directories":{},"maintainers":[{"name":"harshitpanchal","email":"harshitpanchal.ai@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/llamaindex-adapter_0.5.0_1785130097251_0.11873659141616644"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-27T05:28:17.030Z","0.5.0":"2026-07-27T05:28:17.440Z","modified":"2026-07-27T05:28:17.866Z"},"maintainers":[{"name":"harshitpanchal","email":"harshitpanchal.ai@gmail.com"}],"description":"LlamaIndex adapter for Context Router - Vector search, semantic retrieval, and chat memory","homepage":"https://github.com/mindlever-strategy/context-router#readme","keywords":["context-router","llamaindex","mcp","multi-agent","memory","vector-search"],"repository":{"type":"git","url":"git+https://github.com/mindlever-strategy/context-router.git","directory":"packages/llamaindex-adapter"},"bugs":{"url":"https://github.com/mindlever-strategy/context-router/issues"},"license":"Apache-2.0","readme":"# LlamaIndex Adapter for Context Router\n\n[![npm version](https://img.shields.io/npm/v/@context-router/llamaindex-adapter)](https://www.npmjs.com/package/@context-router/llamaindex-adapter)\n\nBridges Context Router's structured state with LlamaIndex's powerful retrieval capabilities. This adapter enables vector search, semantic retrieval, chat memory, and automatic state synchronization for multi-agent workflows.\n\n## Features\n\n- **Vector Search** - Index and search workflow state semantically\n- **Semantic Retrieval** - Query workflow data using natural language\n- **Chat Memory** - Persistent chat history for agents with CRUD operations\n- **Query Engine** - Natural language queries across multiple data sources\n- **State Sync** - Automatic synchronization of state changes to vector index\n- **Re-ranking** - Advanced retrieval with term matching and scoring\n- **Knowledge Graphs** - Entity extraction and relationship mapping\n- **MCP Tools** - Ready-to-use MCP tool definitions\n\n## Installation\n\n```bash\nnpm install @context-router/llamaindex-adapter\n```\n\n**Peer Dependencies:**\n- `@context-router/sdk` ^0.5.0\n- `llamaindex` ^0.5.0\n\n## Quick Start\n\n```typescript\nimport {\n  ContextRouterDocumentStore,\n  ContextRouterChatMemory,\n  ContextRouterQueryEngine,\n  StateSyncService\n} from '@context-router/llamaindex-adapter';\n\n// Initialize Context Router\nconst router = await ContextRouter.local();\n\n// Create document store for vector search\nconst docStore = new ContextRouterDocumentStore({\n  router,\n  workspaceId: 'ws-123',\n});\n\n// Index a workflow\nawait docStore.indexWorkflow(workflowId);\n\n// Query with natural language\nconst results = await docStore.query(\n  'Find similar lead qualification workflows that resulted in confirmed status'\n);\n\n// Create query engine for comprehensive queries\nconst queryEngine = new ContextRouterQueryEngine({\n  router,\n  workspaceId: 'ws-123',\n  sources: {\n    workflowStates: true,\n    chatHistory: true,\n  },\n  synthesisOptions: {\n    llmProvider: 'anthropic',\n    llmModel: 'claude-haiku-4-5',\n  },\n});\n\n// Query across all sources\nconst response = await queryEngine.query(\n  'What approaches worked for enterprise deals?',\n  { workflowId }\n);\n```\n\n## Document Store\n\nIndex workflow state for semantic search:\n\n```typescript\nconst docStore = new ContextRouterDocumentStore({\n  router,\n  workspaceId,\n  documentOptions: {\n    includeMetadata: true,\n    chunkSize: 512,\n    chunkOverlap: 50,\n  },\n});\n\n// Index and query\nawait docStore.indexWorkflow(workflowId);\nconst results = await docStore.query('similar leads', { topK: 5 });\n```\n\n### API\n\n| Method | Description |\n|--------|-------------|\n| `indexWorkflow(workflowId)` | Index a workflow's current state |\n| `indexStateKey(workflowId, key)` | Index a single state key |\n| `indexCheckpoint(checkpointId)` | Index a checkpoint snapshot |\n| `query(query, options?)` | Semantic search with natural language |\n| `similaritySearch(embedding, k)` | Search by embedding vector |\n| `deleteWorkflow(workflowId)` | Remove workflow from index |\n| `getIndexStats()` | Get index statistics |\n\n## Chat Memory\n\nPersistent chat history with retrieval strategies:\n\n```typescript\nconst memory = new ContextRouterChatMemory({\n  router,\n  workspaceId,\n  workflowId,\n  memoryOptions: {\n    lastNMessages: 50,\n    recallStrategy: 'hybrid', // 'recent' | 'relevant' | 'hybrid'\n    relevanceThreshold: 0.7,\n  },\n});\n\n// Add messages\nawait memory.put({ role: 'user', content: 'Hello!' });\nawait memory.put({ role: 'assistant', content: 'How can I help?' });\n\n// Get context\nconst context = await memory.getContext('What did the user ask?');\n\n// Format for LLM\nconst messages = await memory.formatMessages('You are a helpful assistant');\n```\n\n### API\n\n| Method | Description |\n|--------|-------------|\n| `put(message)` | Add a message (returns with ID) |\n| `get(id)` | Get message by ID |\n| `update(id, updates)` | Update a message |\n| `delete(id)` | Delete a message |\n| `getHistory(limit?)` | Get message history |\n| `getByRole(role)` | Get messages by role |\n| `getContext(query?)` | Get context with recall strategy |\n| `formatMessages(prompt?)` | Format for LLM consumption |\n| `search(query)` | Search messages by content |\n| `prune(max?)` | Remove old messages |\n| `clear()` | Clear all messages |\n\n## Retrieval Pipeline\n\nAdvanced retrieval with re-ranking:\n\n```typescript\nconst retriever = new ContextRouterRetriever({\n  router,\n  workspaceId,\n  similarityTopK: 10,\n  reranking: {\n    enabled: true,\n    topN: 5,\n    scoreThreshold: 0.5,\n  },\n  hybridSearch: true,\n  hybridAlpha: 0.5, // 0 = keyword, 1 = vector\n});\n\n// Basic retrieval\nconst results = await retriever.retrieve('enterprise leads');\n\n// Hybrid search\nconst hybridResults = await retriever.hybridRetrieve('confirmed deals', 5);\n```\n\n### Re-ranking Features\n\n- **Term Matching Boost** - Scores based on query term overlap\n- **Hybrid Search** - Combines vector and keyword search\n- **Score Threshold** - Filter low-confidence results\n- **Deduplication** - Combines results from multiple sources\n\n## Query Engine\n\nMulti-source query with synthesis:\n\n```typescript\nconst engine = new ContextRouterQueryEngine({\n  router,\n  workspaceId,\n  sources: {\n    workflowStates: true,\n    checkpoints: true,\n    chatHistory: true,\n    eventJournal: false,\n  },\n  retrieverOptions: {\n    similarityTopK: 5,\n  },\n  synthesisOptions: {\n    llmProvider: 'anthropic',\n    llmModel: 'claude-haiku-4-5',\n    includeSources: true,\n  },\n});\n\n// Index workflow for retrieval\nawait engine.indexWorkflow(workflowId);\n\n// Simple query\nconst response = await engine.query('What worked for similar leads?', {\n  workflowId,\n});\n\n// LLM-powered synthesis\nconst llmResponse = await engine.queryWithLLM(\n  'Summarize the key decisions in this workflow',\n  { workflowId }\n);\n```\n\n## State Sync Service\n\nAutomatic synchronization of state changes:\n\n```typescript\nconst sync = new StateSyncService({\n  router,\n  workspaceId,\n  triggers: {\n    onStateWrite: true,\n    onCheckpoint: true,\n    onWorkflowComplete: false,\n  },\n  syncOptions: {\n    batchSize: 100,\n    debounceMs: 1000,\n    retryAttempts: 3,\n  },\n  includePatterns: ['lead_*', 'customer_*'],\n  excludePatterns: ['cache_*', 'temp_*'],\n});\n\n// Register event handler\nsync.onSync(async (event) => {\n  console.log(`Synced: ${event.type} for workflow ${event.workflowId}`);\n});\n\n// Start syncing\nawait sync.start();\n\n// Manual sync\nawait sync.syncWorkflow(workflowId);\nawait sync.syncStateKey(workflowId, 'lead_status');\n\n// Stop when done\nawait sync.stop();\n```\n\n### API\n\n| Method | Description |\n|--------|-------------|\n| `start()` | Start the sync service |\n| `stop()` | Stop the sync service |\n| `syncWorkflow(workflowId)` | Sync entire workflow state |\n| `syncStateKey(workflowId, key)` | Sync specific state key |\n| `syncFromCheckpoint(workflowId, checkpointId)` | Sync from checkpoint |\n| `onWorkflowComplete(workflowId)` | Handle workflow completion |\n| `flush()` | Flush pending syncs |\n| `onSync(handler)` | Register event handler |\n| `getStats()` | Get sync statistics |\n\n## MCP Tools\n\nReady-to-use MCP tool definitions:\n\n```typescript\nimport {\n  mcpTools,\n  handleIndexWorkflow,\n  handleSearchWorkflow,\n  handleQueryMemory,\n} from '@context-router/llamaindex-adapter/mcp';\n\n// Available tools\nfor (const tool of mcpTools) {\n  console.log(`${tool.name}: ${tool.description}`);\n}\n\n// Handle tool calls\nconst result = await handleIndexWorkflow(\n  { workspaceId: 'ws-123', workflowId: 'wf-456' },\n  { router, workspaceId: 'ws-123' }\n);\n```\n\n### Available Tools\n\n| Tool | Description |\n|------|-------------|\n| `index_workflow` | Index a workflow's state for semantic search |\n| `search_workflow` | Semantic search over workflow data |\n| `query_memory` | Query chat memory with natural language |\n| `extract_knowledge` | Extract entities and relationships |\n| `sync_state` | Synchronize workflow state to vector index |\n\n## TypeScript\n\nFull TypeScript support with type exports:\n\n```typescript\nimport type {\n  WorkflowState,\n  CheckpointData,\n  EmbeddingConfig,\n  VectorStoreConfig,\n  QueryOptions,\n  IndexStats,\n  Entity,\n  Relationship,\n} from '@context-router/llamaindex-adapter';\n```\n\n## Environment Variables\n\n```bash\n# LlamaIndex adapter settings\nLLAMA_INDEX_ADAPTER_ENABLED=true\n\n# Vector store\nVECTOR_STORE_TYPE=pgvector  # or 'chromadb', 'qdrant', 'in-memory'\nDATABASE_URL=postgresql://...\n\n# For ChromaDB\nCHROMA_HOST=localhost\nCHROMA_PORT=8000\n\n# For Qdrant\nQDRANT_URL=http://localhost:6333\nQDRANT_API_KEY=...\n```\n\n## Comparison with Other Adapters\n\n| Feature | LangGraph | CREWAI | LlamaIndex |\n|---------|-----------|--------|------------|\n| State sync | Yes | Yes | Yes |\n| Checkpoint restore | Yes | Yes | Yes |\n| Handoff summaries | Yes | Yes | Yes |\n| Vector search | No | No | **Yes** |\n| Semantic retrieval | No | No | **Yes** |\n| Knowledge graphs | No | No | **Yes** |\n| Chat memory | No | Yes | Yes |\n| Tool integration | Yes | Yes | Yes |\n\n## License\n\nApache 2.0\n","readmeFilename":"README.md","_rev":"1-6bb9d9a0a0788276525cc69e30af5ca8"}