{"_id":"@aivue/hierarchical-memory","name":"@aivue/hierarchical-memory","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@aivue/hierarchical-memory","version":"1.0.0","description":"Hierarchical memory trees (H-MEM style) for LLM tools and agents, optimized for tables and documents","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"},"./hierarchical-memory.css":"./dist/hierarchical-memory.css","./dist/hierarchical-memory.css":"./dist/hierarchical-memory.css"},"scripts":{"build":"npm run clean && vite build && npm run postbuild","dev":"vite build --watch","clean":"rm -rf dist","test":"vitest run","test:watch":"vitest","prepublishOnly":"npm run build","postbuild":"cp README.md dist/ 2>/dev/null || true"},"keywords":["vue","ai","llm","memory","hierarchical","h-mem","hiagent","context","tree","semantic","rag","retrieval"],"author":{"name":"reachbrt"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/reachbrt/vueai.git","directory":"packages/hierarchical-memory"},"peerDependencies":{"vue":"^2.6.0 || ^3.0.0"},"dependencies":{"@aivue/core":"file:../core"},"devDependencies":{"@vitejs/plugin-vue":"^5.0.0","@vue/test-utils":"^2.4.0","typescript":"^5.0.0","vite":"^5.0.0","vite-plugin-dts":"^3.7.0","vitest":"^1.0.0","vue":"^3.4.0"},"_id":"@aivue/hierarchical-memory@1.0.0","gitHead":"5d6b23d30fd6d96dde4d4d14dce1fe9355158871","bugs":{"url":"https://github.com/reachbrt/vueai/issues"},"homepage":"https://github.com/reachbrt/vueai#readme","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-cdeQEBFmuGzdyTqyhVLFdXvcW8JKINYtG3/kG+G/Yxr8eR/XzipOKgIrzM1vZsG6ge7MJgJt9BXn+yuPZRj17Q==","shasum":"c0031ffb9d0914f9a7ccad563bb1a2131f667ed3","tarball":"https://registry.npmjs.org/@aivue/hierarchical-memory/-/hierarchical-memory-1.0.0.tgz","fileCount":15,"unpackedSize":180643,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAQ2Ed6OmFQGvu7SHfAIu1keDlPRhAaAZSQvF4q8LjP5AiEAtPCumgy9vdSD4xBZqmbnSQkbylcfWUImIilee2PTlsI="}]},"_npmUser":{"name":"aivue","email":"reachbrt@gmail.com"},"directories":{},"maintainers":[{"name":"aivue","email":"reachbrt@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hierarchical-memory_1.0.0_1768888919676_0.7852100740343859"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-20T06:01:59.564Z","1.0.0":"2026-01-20T06:01:59.826Z","modified":"2026-01-20T06:02:00.068Z"},"maintainers":[{"name":"aivue","email":"reachbrt@gmail.com"}],"description":"Hierarchical memory trees (H-MEM style) for LLM tools and agents, optimized for tables and documents","homepage":"https://github.com/reachbrt/vueai#readme","keywords":["vue","ai","llm","memory","hierarchical","h-mem","hiagent","context","tree","semantic","rag","retrieval"],"repository":{"type":"git","url":"git+https://github.com/reachbrt/vueai.git","directory":"packages/hierarchical-memory"},"author":{"name":"reachbrt"},"bugs":{"url":"https://github.com/reachbrt/vueai/issues"},"license":"MIT","readme":"# @aivue/hierarchical-memory\n\n> Hierarchical memory trees (H-MEM style) for LLM tools and agents, optimized for tables and documents\n\n[![npm version](https://img.shields.io/npm/v/@aivue/hierarchical-memory.svg)](https://www.npmjs.com/package/@aivue/hierarchical-memory)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## 🎯 Features\n\n- **Multi-Level Memory Tree** - Organize context as a hierarchical tree with automatic summarization\n- **Semantic Retrieval** - Find relevant nodes using embeddings or keyword matching\n- **LLM Integration** - Built-in support for OpenAI and Anthropic for summarization\n- **Flexible Operations** - Insert, update, delete, promote, demote nodes\n- **Vue Components** - Beautiful tree visualization with interactive UI\n- **TypeScript** - Full type safety and IntelliSense support\n- **Table & Document Support** - Optimized for structured and unstructured data\n\n## 📦 Installation\n\n```bash\nnpm install @aivue/hierarchical-memory\n```\n\n## 🚀 Quick Start\n\n### Basic Usage\n\n```typescript\nimport { HierarchicalMemory, NodeType, NodeLevel } from '@aivue/hierarchical-memory';\n\n// Create memory tree\nconst memory = new HierarchicalMemory({\n  autoSummarize: true,\n  summarization: {\n    provider: 'openai',\n    apiKey: 'your-api-key',\n  },\n});\n\n// Insert documents\nawait memory.insert('Long document content...', {\n  type: NodeType.DOCUMENT,\n  metadata: { title: 'My Document' },\n});\n\n// Retrieve relevant context\nconst result = await memory.retrieve('What is this about?');\nconsole.log(result.context); // Formatted for LLM\n```\n\n### Vue Composable\n\n```vue\n<script setup>\nimport { useHierarchicalMemory } from '@aivue/hierarchical-memory';\nimport { NodeType } from '@aivue/hierarchical-memory';\n\nconst { insert, retrieve, nodes, stats } = useHierarchicalMemory({\n  autoSummarize: true,\n});\n\n// Insert content\nconst nodeId = await insert('Document content', {\n  type: NodeType.DOCUMENT,\n  metadata: { title: 'Example' },\n});\n\n// Query\nconst result = await retrieve('search query');\n</script>\n```\n\n### Vue Component\n\n```vue\n<template>\n  <MemoryTreeViewer\n    :nodes=\"nodes\"\n    :stats=\"stats\"\n    @select=\"handleSelect\"\n    @delete=\"handleDelete\"\n  />\n</template>\n\n<script setup>\nimport { MemoryTreeViewer } from '@aivue/hierarchical-memory';\nimport '@aivue/hierarchical-memory/dist/hierarchical-memory.css';\n</script>\n```\n\n## 📚 Core Concepts\n\n### Node Levels\n\n- **LEAF (0)** - Raw data chunks, table rows\n- **L1 (1)** - First-level summaries\n- **L2 (2)** - Second-level summaries\n- **L3 (3)** - Third-level summaries\n- **ROOT (4)** - Top-level overview\n\n### Node Types\n\n- **DOCUMENT** - Text documents\n- **TABLE** - Structured tables\n- **CHUNK** - Text chunks\n- **SUMMARY** - Generated summaries\n- **REFERENCE** - References to other nodes\n\n## 🔧 API Reference\n\n### HierarchicalMemory\n\n```typescript\nclass HierarchicalMemory {\n  constructor(config?: HMemConfig);\n  \n  // Core operations\n  insert(content: string, options: InsertOptions): Promise<string>;\n  update(nodeId: string, content: string): Promise<void>;\n  delete(nodeId: string, deleteChildren?: boolean): void;\n  \n  // Hierarchy operations\n  promote(nodeId: string, options: PromotionOptions): Promise<void>;\n  demote(nodeId: string, targetLevel: NodeLevel): void;\n  \n  // Retrieval\n  retrieve(query: string, config?: RetrievalConfig): Promise<QueryResult>;\n  \n  // Export\n  export(options?: ExportOptions): string;\n  \n  // Stats\n  getStats(): TreeStats;\n}\n```\n\n### Configuration\n\n```typescript\ninterface HMemConfig {\n  maxDepth?: number;              // Default: 4\n  maxChildrenPerNode?: number;    // Default: 10\n  autoPromote?: boolean;          // Default: false\n  autoSummarize?: boolean;        // Default: true\n  summarization?: {\n    provider: 'openai' | 'anthropic' | 'custom';\n    apiKey?: string;\n    model?: string;\n    maxTokens?: number;\n    customSummarizer?: (content: string) => Promise<string>;\n  };\n  enableEmbeddings?: boolean;     // Default: false\n  embeddingProvider?: 'openai' | 'custom';\n  customEmbedder?: (text: string) => Promise<number[]>;\n}\n```\n\n## 💡 Use Cases\n\n### 1. Document Management\n\n```typescript\n// Insert large document\nconst docId = await memory.insert(largeDocument, {\n  type: NodeType.DOCUMENT,\n  metadata: { title: 'Research Paper', source: 'arxiv' },\n  autoSummarize: true,\n});\n\n// Retrieve relevant sections\nconst result = await memory.retrieve('methodology section');\n```\n\n### 2. Table Processing\n\n```typescript\nimport { parseTable, formatTableAsMarkdown } from '@aivue/hierarchical-memory';\n\n// Parse and insert table\nconst rows = parseTable(csvContent, 'csv');\nconst markdown = formatTableAsMarkdown(rows);\n\nawait memory.insert(markdown, {\n  type: NodeType.TABLE,\n  metadata: { title: 'Sales Data' },\n});\n```\n\n### 3. Multi-Level Summarization\n\n```typescript\n// Insert raw chunks\nfor (const chunk of chunks) {\n  await memory.insert(chunk, {\n    type: NodeType.CHUNK,\n    level: NodeLevel.LEAF,\n  });\n}\n\n// Promote important nodes\nawait memory.promote(nodeId, {\n  targetLevel: NodeLevel.L2,\n  autoSummarize: true,\n});\n```\n\n## 🎨 Styling\n\nImport the CSS file:\n\n```typescript\nimport '@aivue/hierarchical-memory/dist/hierarchical-memory.css';\n```\n\nOr customize with CSS variables:\n\n```css\n.memory-tree-viewer {\n  --color-primary: #3b82f6;\n  --color-border: #e2e8f0;\n  --color-bg: #ffffff;\n}\n```\n\n## 📖 Examples\n\nSee the [demo folder](../../demo) for complete examples.\n\n## 🤝 Contributing\n\nContributions are welcome! Please read our [Contributing Guide](../../CONTRIBUTING.md).\n\n## 📄 License\n\nMIT © [reachbrt](https://github.com/reachbrt)\n\n## 🔗 Links\n\n- [GitHub](https://github.com/reachbrt/vueai)\n- [npm](https://www.npmjs.com/package/@aivue/hierarchical-memory)\n- [Documentation](https://aivue.netlify.app)\n\n","readmeFilename":"README.md","_rev":"1-aaffda0a6649c831a825b4a60343a74e"}