@easbot/note 0.1.11 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -1,3 +1,5 @@
1
+ [中文](./README.md) | English
2
+
1
3
  # @easbot/note
2
4
 
3
5
  > Note Knowledge Base - Unstructured Memory and Document Knowledge Base Management System
@@ -19,8 +21,6 @@ Note Knowledge Base is a TypeScript/Node.js-based unstructured memory and docume
19
21
  ## Installation
20
22
 
21
23
  ```bash
22
- npm install @easbot/note
23
- # or
24
24
  pnpm add @easbot/note
25
25
  ```
26
26
 
@@ -31,14 +31,13 @@ pnpm add @easbot/note
31
31
  ```typescript
32
32
  import { NoteKnowledge } from '@easbot/note';
33
33
 
34
- // Create knowledge base instance
35
34
  const kb = new NoteKnowledge({
36
35
  storagePath: './data/knowledge.db',
37
36
  vectorDims: 768,
38
37
  chunkSize: 1000,
39
38
  chunkOverlap: 200,
40
- embedding: yourEmbeddingModel, // AI SDK EmbeddingModelV2
41
- llm: yourLLM, // Optional, for entity extraction
39
+ embedding: yourEmbeddingModel,
40
+ llm: yourLLM,
42
41
  hybridSearch: {
43
42
  vectorWeight: 0.7,
44
43
  ftsWeight: 0.3,
@@ -47,165 +46,48 @@ const kb = new NoteKnowledge({
47
46
  },
48
47
  });
49
48
 
50
- // Initialize
51
49
  await kb.initialize();
52
50
 
53
- // Ingest document
54
51
  const result = await kb.ingestDocument('./docs/example.md');
55
52
  console.log(`Created ${result.chunksCreated} chunks`);
56
53
 
57
- // Search
58
54
  const results = await kb.search('query content', { limit: 10 });
59
55
  for (const r of results) {
60
56
  console.log(`[${r.score}] ${r.content}`);
61
57
  }
62
58
 
63
- // Close connection
64
59
  await kb.close();
65
60
  ```
66
61
 
67
62
  ### Graph Queries
68
63
 
69
64
  ```typescript
70
- // Create nodes
71
65
  const node1 = await kb.createNode('EntityA', 'Type1', { prop: 'value' });
72
66
  const node2 = await kb.createNode('EntityB', 'Type1');
73
67
 
74
- // Create edge
75
68
  const edge = await kb.createEdge(node1.id, node2.id, 'RELATED_TO');
76
69
 
77
- // Find path
78
70
  const paths = await kb.findPath('EntityA', 'EntityB', 3);
79
71
 
80
- // SQL query
81
72
  const nodes = await kb.queryNodes('SELECT * FROM nodes WHERE type = ?', ['Type1']);
82
73
  ```
83
74
 
84
- ## API Documentation
85
-
86
- ### NoteKnowledge
87
-
88
- #### Constructor
89
-
90
- ```typescript
91
- constructor(config: NoteKnowledgeConfig)
92
- ```
93
-
94
- Configuration options:
95
- - `storagePath`: Database storage path
96
- - `vectorDims`: Vector dimensions (default 768)
97
- - `chunkSize`: Chunk size (default 1000)
98
- - `chunkOverlap`: Chunk overlap (default 200)
99
- - `embedding`: Embedding model (AI SDK EmbeddingModelV2)
100
- - `llm`: LLM model (optional, for summary generation)
101
- - `graphLlm`: Graph LLM (optional, for entity extraction)
102
- - `rerankLlm`: Rerank LLM (optional)
103
- - `hybridSearch`: Hybrid search weight configuration
104
-
105
- #### Document Operations
106
-
107
- - `initialize()`: Initialize knowledge base
108
- - `ingestDocument(filePath)`: Ingest single document
109
- - `ingestDocuments(filePaths, progress?)`: Batch ingest documents
110
- - `removeDocument(filePath)`: Remove document
111
-
112
- #### Search Operations
113
-
114
- - `search(query, options?)`: Hybrid search
115
-
116
- #### Graph Operations
117
-
118
- - `queryNodes(sql, params?)`: SQL query for nodes
119
- - `queryEdges(sql, params?)`: SQL query for edges
120
- - `findPath(startNode, endNode, maxDepth?)`: Find path
121
- - `createNode(name, type, properties?)`: Create node
122
- - `updateNode(id, properties)`: Update node
123
- - `deleteNode(id)`: Delete node
124
- - `createEdge(source, target, relation, properties?)`: Create edge
125
- - `deleteEdge(id)`: Delete edge
126
-
127
- #### Status and Lifecycle
128
-
129
- - `getStatus()`: Get knowledge base status
130
- - `healthCheck()`: Health check
131
- - `close()`: Close connection
132
-
133
- ## Data Models
134
-
135
- ### Document
136
-
137
- ```typescript
138
- interface Document {
139
- id: number;
140
- path: string;
141
- title?: string;
142
- contentHash: string;
143
- summary?: string;
144
- metadata?: Record<string, unknown>;
145
- lastModified: number;
146
- }
147
- ```
148
-
149
- ### Node
150
-
151
- ```typescript
152
- interface Node {
153
- id: number;
154
- name: string;
155
- type: string;
156
- properties?: Record<string, unknown>;
157
- createdAt: number;
158
- updatedAt: number;
159
- }
160
- ```
75
+ ## Development
161
76
 
162
- ### Edge
77
+ ```bash
78
+ # Install dependencies
79
+ pnpm install
163
80
 
164
- ```typescript
165
- interface Edge {
166
- id: number;
167
- source: number;
168
- target: number;
169
- relation: string;
170
- properties?: Record<string, unknown>;
171
- createdAt: number;
172
- }
173
- ```
81
+ # Build
82
+ pnpm build
174
83
 
175
- ### SearchResult
84
+ # Test
85
+ pnpm test
176
86
 
177
- ```typescript
178
- interface SearchResult {
179
- id: number;
180
- content: string;
181
- score: number;
182
- path: string;
183
- startLine: number;
184
- endLine: number;
185
- documentId: number;
186
- }
87
+ # Type check
88
+ pnpm type-check
187
89
  ```
188
90
 
189
- ## Hybrid Search
190
-
191
- The system supports three search methods:
192
-
193
- 1. **Vector Search**: Cosine similarity based on embedding vectors
194
- 2. **Full-Text Search**: SQLite FTS5 with porter stemmer and unicode61 tokenizer
195
- 3. **Graph Search**: Graph traversal based on entity relationships
196
-
197
- Results are merged using weighted score combination with configurable weights for each method.
198
-
199
- ## Dependencies
200
-
201
- - `better-sqlite3`: SQLite database
202
- - `@easbot/utils`: Utility library (Markdown parsing, intelligent chunking)
203
- - `ai`: AI SDK
204
-
205
91
  ## License
206
92
 
207
93
  MIT
208
-
209
- ## Author
210
-
211
- houjallen
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [English](./README.en.md) | 中文
2
+
1
3
  # @easbot/note
2
4
 
3
5
  > Note Knowledge Base - 非结构化记忆和文档知识库管理系统
@@ -19,8 +21,6 @@ Note Knowledge Base 是一个基于 TypeScript/Node.js 的非结构化记忆和
19
21
  ## 安装
20
22
 
21
23
  ```bash
22
- npm install @easbot/note
23
- # 或
24
24
  pnpm add @easbot/note
25
25
  ```
26
26
 
@@ -31,14 +31,13 @@ pnpm add @easbot/note
31
31
  ```typescript
32
32
  import { NoteKnowledge } from '@easbot/note';
33
33
 
34
- // 创建知识库实例
35
34
  const kb = new NoteKnowledge({
36
35
  storagePath: './data/knowledge.db',
37
36
  vectorDims: 768,
38
37
  chunkSize: 1000,
39
38
  chunkOverlap: 200,
40
- embedding: yourEmbeddingModel, // AI SDK EmbeddingModelV2
41
- llm: yourLLM, // 可选,用于实体提取
39
+ embedding: yourEmbeddingModel,
40
+ llm: yourLLM,
42
41
  hybridSearch: {
43
42
  vectorWeight: 0.7,
44
43
  ftsWeight: 0.3,
@@ -47,165 +46,48 @@ const kb = new NoteKnowledge({
47
46
  },
48
47
  });
49
48
 
50
- // 初始化
51
49
  await kb.initialize();
52
50
 
53
- // 摄取文档
54
51
  const result = await kb.ingestDocument('./docs/example.md');
55
52
  console.log(`创建了 ${result.chunksCreated} 个块`);
56
53
 
57
- // 搜索
58
54
  const results = await kb.search('查询内容', { limit: 10 });
59
55
  for (const r of results) {
60
56
  console.log(`[${r.score}] ${r.content}`);
61
57
  }
62
58
 
63
- // 关闭连接
64
59
  await kb.close();
65
60
  ```
66
61
 
67
62
  ### 图查询
68
63
 
69
64
  ```typescript
70
- // 创建节点
71
65
  const node1 = await kb.createNode('实体A', '类型1', { prop: 'value' });
72
66
  const node2 = await kb.createNode('实体B', '类型1');
73
67
 
74
- // 创建边
75
68
  const edge = await kb.createEdge(node1.id, node2.id, 'RELATED_TO');
76
69
 
77
- // 查找路径
78
70
  const paths = await kb.findPath('实体A', '实体B', 3);
79
71
 
80
- // SQL 查询
81
72
  const nodes = await kb.queryNodes('SELECT * FROM nodes WHERE type = ?', ['类型1']);
82
73
  ```
83
74
 
84
- ## API 文档
85
-
86
- ### NoteKnowledge
87
-
88
- #### 构造函数
89
-
90
- ```typescript
91
- constructor(config: NoteKnowledgeConfig)
92
- ```
93
-
94
- 配置选项:
95
- - `storagePath`: 数据库存储路径
96
- - `vectorDims`: 向量维度(默认 768)
97
- - `chunkSize`: 分块大小(默认 1000)
98
- - `chunkOverlap`: 分块重叠(默认 200)
99
- - `embedding`: Embedding 模型(AI SDK EmbeddingModelV2)
100
- - `llm`: LLM 模型(可选,用于摘要生成)
101
- - `graphLlm`: 图 LLM(可选,用于实体提取)
102
- - `rerankLlm`: 重排序 LLM(可选)
103
- - `hybridSearch`: 混合搜索权重配置
104
-
105
- #### 文档操作
106
-
107
- - `initialize()`: 初始化知识库
108
- - `ingestDocument(filePath)`: 摄取单个文档
109
- - `ingestDocuments(filePaths, progress?)`: 批量摄取文档
110
- - `removeDocument(filePath)`: 删除文档
111
-
112
- #### 搜索操作
113
-
114
- - `search(query, options?)`: 混合搜索
115
-
116
- #### 图操作
117
-
118
- - `queryNodes(sql, params?)`: SQL 查询节点
119
- - `queryEdges(sql, params?)`: SQL 查询边
120
- - `findPath(startNode, endNode, maxDepth?)`: 查找路径
121
- - `createNode(name, type, properties?)`: 创建节点
122
- - `updateNode(id, properties)`: 更新节点
123
- - `deleteNode(id)`: 删除节点
124
- - `createEdge(source, target, relation, properties?)`: 创建边
125
- - `deleteEdge(id)`: 删除边
126
-
127
- #### 状态和生命周期
128
-
129
- - `getStatus()`: 获取知识库状态
130
- - `healthCheck()`: 健康检查
131
- - `close()`: 关闭连接
132
-
133
- ## 数据模型
134
-
135
- ### 文档 (Document)
136
-
137
- ```typescript
138
- interface Document {
139
- id: number;
140
- path: string;
141
- title?: string;
142
- contentHash: string;
143
- summary?: string;
144
- metadata?: Record<string, unknown>;
145
- lastModified: number;
146
- }
147
- ```
148
-
149
- ### 节点 (Node)
150
-
151
- ```typescript
152
- interface Node {
153
- id: number;
154
- name: string;
155
- type: string;
156
- properties?: Record<string, unknown>;
157
- createdAt: number;
158
- updatedAt: number;
159
- }
160
- ```
75
+ ## 开发
161
76
 
162
- ### 边 (Edge)
77
+ ```bash
78
+ # 安装依赖
79
+ pnpm install
163
80
 
164
- ```typescript
165
- interface Edge {
166
- id: number;
167
- source: number;
168
- target: number;
169
- relation: string;
170
- properties?: Record<string, unknown>;
171
- createdAt: number;
172
- }
173
- ```
81
+ # 构建
82
+ pnpm build
174
83
 
175
- ### 搜索结果 (SearchResult)
84
+ # 测试
85
+ pnpm test
176
86
 
177
- ```typescript
178
- interface SearchResult {
179
- id: number;
180
- content: string;
181
- score: number;
182
- path: string;
183
- startLine: number;
184
- endLine: number;
185
- documentId: number;
186
- }
87
+ # 类型检查
88
+ pnpm type-check
187
89
  ```
188
90
 
189
- ## 混合搜索
190
-
191
- 系统支持三种搜索方式的混合:
192
-
193
- 1. **向量搜索**:基于嵌入向量的余弦相似度
194
- 2. **全文搜索**:SQLite FTS5,支持 porter 词干提取和 unicode61 分词
195
- 3. **图搜索**:基于实体关系的图遍历
196
-
197
- 结果合并使用加权分数组合,可配置各搜索方式的权重。
198
-
199
- ## 依赖
200
-
201
- - `better-sqlite3`: SQLite 数据库
202
- - `@easbot/utils`: 工具库(Markdown 解析、智能分块)
203
- - `ai`: AI SDK
204
-
205
91
  ## 许可证
206
92
 
207
93
  MIT
208
-
209
- ## 作者
210
-
211
- houjallen