# @easbot/memory

[English](#english) | [中文](#中文)

---

<a name="中文"></a>

## 中文

EASBOT 生态系统的记忆管理库，提供智能化的记忆索引、搜索和管理功能。

### 特性

- **混合搜索**：支持向量搜索、全文搜索（FTS）和图搜索的混合检索
- **中英文分词**：基于 jieba-wasm 实现高质量中英文分词
- **增量索引**：支持增量更新，自动检测文件变化
- **多源支持**：支持 memory 和 sessions 两种记忆源
- **XDG 规范**：数据库默认存储在 XDG 数据目录

### 安装

```bash
pnpm add @easbot/memory
```

### 使用示例

```typescript
import { MemoryIndexManager } from '@easbot/memory';

// 获取记忆管理器实例
const manager = await MemoryIndexManager.get({
  workspaceDir: '/path/to/workspace',
});

// 搜索记忆
const results = manager.search('机器学习', {
  maxResults: 10,
  minScore: 0.5,
});

// 索引文件
await manager.indexFile('/path/to/file.md');
```

### API

#### MemoryIndexManager

| 方法 | 说明 |
|------|------|
| `get(params)` | 获取或创建管理器实例 |
| `search(query, options)` | 混合搜索 |
| `indexFile(filePath)` | 索引单个文件 |
| `indexDirectory(dirPath)` | 索引目录 |
| `getStatus()` | 获取状态信息 |

### 开发

```bash
# 安装依赖
pnpm install

# 构建
pnpm build

# 测试
pnpm test

# 类型检查
pnpm type-check
```

### 数据库位置

默认存储位置：`$XDG_DATA_HOME/easbot/memory.db`

- Linux: `~/.local/share/easbot/memory.db`
- macOS: `~/Library/Application Support/easbot/memory.db`
- Windows: `%APPDATA%/easbot/memory.db`

---

<a name="english"></a>

## English

Memory management library for the EASBOT ecosystem, providing intelligent memory indexing, search, and management capabilities.

### Features

- **Hybrid Search**: Combines vector search, full-text search (FTS), and graph search
- **Chinese/English Tokenization**: High-quality tokenization via jieba-wasm
- **Incremental Indexing**: Supports incremental updates with automatic file change detection
- **Multi-source Support**: Supports both 'memory' and 'sessions' memory sources
- **XDG Compliance**: Database stored in XDG data directory by default

### Installation

```bash
pnpm add @easbot/memory
```

### Usage

```typescript
import { MemoryIndexManager } from '@easbot/memory';

// Get memory manager instance
const manager = await MemoryIndexManager.get({
  workspaceDir: '/path/to/workspace',
});

// Search memories
const results = manager.search('machine learning', {
  maxResults: 10,
  minScore: 0.5,
});

// Index a file
await manager.indexFile('/path/to/file.md');
```

### API

#### MemoryIndexManager

| Method | Description |
|--------|-------------|
| `get(params)` | Get or create manager instance |
| `search(query, options)` | Hybrid search |
| `indexFile(filePath)` | Index a single file |
| `indexDirectory(dirPath)` | Index a directory |
| `getStatus()` | Get status information |

### Development

```bash
# Install dependencies
pnpm install

# Build
pnpm build

# Test
pnpm test

# Type check
pnpm type-check
```

### Database Location

Default storage: `$XDG_DATA_HOME/easbot/memory.db`

- Linux: `~/.local/share/easbot/memory.db`
- macOS: `~/Library/Application Support/easbot/memory.db`
- Windows: `%APPDATA%/easbot/memory.db`

## License

MIT
