@customize-agent/knowledge 4.0.1 → 4.0.3
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/dist/chunking/bge-tokenizer.d.ts +12 -0
- package/dist/chunking/bge-tokenizer.js +70 -0
- package/dist/chunking/text-chunker.d.ts +20 -0
- package/dist/chunking/text-chunker.js +166 -53
- package/dist/classification/classifier.d.ts +1 -0
- package/dist/classification/classifier.js +1 -1
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +7 -0
- package/dist/core/change-tracker.d.ts +13 -0
- package/dist/core/change-tracker.js +13 -0
- package/dist/core/file-scanner.d.ts +13 -0
- package/dist/core/file-scanner.js +12 -0
- package/dist/core/index-state-store.d.ts +67 -0
- package/dist/core/index-state-store.js +204 -50
- package/dist/core/knowledge-base-manager.d.ts +24 -2
- package/dist/core/knowledge-base-manager.js +204 -52
- package/dist/core/multi-project-manager.d.ts +10 -0
- package/dist/core/multi-project-manager.js +21 -2
- package/dist/core/project-config.d.ts +4 -0
- package/dist/core/project-config.js +4 -0
- package/dist/core/project-id.d.ts +5 -0
- package/dist/core/project-id.js +5 -0
- package/dist/core/project-registry.d.ts +1 -0
- package/dist/core/project-registry.js +1 -0
- package/dist/dedup/dedup-engine.d.ts +3 -0
- package/dist/dedup/dedup-engine.js +1 -0
- package/dist/dedup/relationship-detector.d.ts +7 -0
- package/dist/dedup/relationship-detector.js +7 -0
- package/dist/embedding/embedding-provider.d.ts +32 -0
- package/dist/embedding/embedding-provider.js +136 -2
- package/dist/extraction/content-extractor.d.ts +32 -2
- package/dist/extraction/content-extractor.js +524 -124
- package/dist/extraction/external-extractor.d.ts +10 -0
- package/dist/extraction/external-extractor.js +6 -0
- package/dist/extraction/module-resolver.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/search/federation-search.d.ts +8 -0
- package/dist/search/federation-search.js +2 -0
- package/dist/types.d.ts +10 -0
- package/dist/vector/collection-manager.d.ts +3 -0
- package/dist/vector/collection-manager.js +3 -0
- package/dist/vector/hnsw-vector-store.d.ts +21 -0
- package/dist/vector/hnsw-vector-store.js +108 -0
- package/dist/vector/types.d.ts +8 -0
- package/dist/vector/vector-indexer.d.ts +15 -1
- package/dist/vector/vector-indexer.js +34 -5
- package/models/bge-small-zh-v1.5/config.json +31 -0
- package/models/bge-small-zh-v1.5/onnx/model_quantized.onnx +0 -0
- package/models/bge-small-zh-v1.5/special_tokens_map.json +7 -0
- package/models/bge-small-zh-v1.5/tokenizer.json +21278 -0
- package/models/bge-small-zh-v1.5/tokenizer_config.json +15 -0
- package/package.json +16 -9
- package/scripts/install-hnsw.cjs +47 -0
- package/dist/vector/sqlite-vec-store.d.ts +0 -38
- package/dist/vector/sqlite-vec-store.js +0 -203
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"clean_up_tokenization_spaces": true,
|
|
3
|
+
"cls_token": "[CLS]",
|
|
4
|
+
"do_basic_tokenize": true,
|
|
5
|
+
"do_lower_case": false,
|
|
6
|
+
"mask_token": "[MASK]",
|
|
7
|
+
"model_max_length": 512,
|
|
8
|
+
"never_split": null,
|
|
9
|
+
"pad_token": "[PAD]",
|
|
10
|
+
"sep_token": "[SEP]",
|
|
11
|
+
"strip_accents": null,
|
|
12
|
+
"tokenize_chinese_chars": true,
|
|
13
|
+
"tokenizer_class": "BertTokenizer",
|
|
14
|
+
"unk_token": "[UNK]"
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@customize-agent/knowledge",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Local knowledge base infrastructure for customize-agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,6 +12,14 @@
|
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"prebuild": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint src/",
|
|
20
|
+
"postinstall": "node scripts/install-hnsw.cjs",
|
|
21
|
+
"doctor:hnsw": "node scripts/install-hnsw.cjs"
|
|
22
|
+
},
|
|
15
23
|
"license": "MIT",
|
|
16
24
|
"engines": {
|
|
17
25
|
"node": ">=22.13.0"
|
|
@@ -23,7 +31,9 @@
|
|
|
23
31
|
"directory": "packages/knowledge"
|
|
24
32
|
},
|
|
25
33
|
"files": [
|
|
26
|
-
"dist"
|
|
34
|
+
"dist",
|
|
35
|
+
"models",
|
|
36
|
+
"scripts"
|
|
27
37
|
],
|
|
28
38
|
"publishConfig": {
|
|
29
39
|
"access": "public"
|
|
@@ -35,6 +45,7 @@
|
|
|
35
45
|
"knowledge-base"
|
|
36
46
|
],
|
|
37
47
|
"dependencies": {
|
|
48
|
+
"@huggingface/transformers": "^3.8.0",
|
|
38
49
|
"@napi-rs/canvas": "^0.1.82",
|
|
39
50
|
"better-sqlite3": "^12.10.0",
|
|
40
51
|
"dwgdxf": "^2.0.1",
|
|
@@ -44,7 +55,8 @@
|
|
|
44
55
|
"mammoth": "^1.12.0",
|
|
45
56
|
"pdf-parse": "^2.4.5",
|
|
46
57
|
"pdfjs-dist": "^5.4.394",
|
|
47
|
-
"
|
|
58
|
+
"hnswlib-node": "^3.0.0",
|
|
59
|
+
"node-gyp": "^12.1.0",
|
|
48
60
|
"tesseract.js": "^7.0.0",
|
|
49
61
|
"word-extractor": "^1.0.4",
|
|
50
62
|
"xlsx": "^0.18.5"
|
|
@@ -52,10 +64,5 @@
|
|
|
52
64
|
"devDependencies": {
|
|
53
65
|
"@types/better-sqlite3": "^7.6.13",
|
|
54
66
|
"@types/node": "^25.9.3"
|
|
55
|
-
},
|
|
56
|
-
"scripts": {
|
|
57
|
-
"build": "tsc",
|
|
58
|
-
"typecheck": "tsc --noEmit",
|
|
59
|
-
"lint": "eslint src/"
|
|
60
67
|
}
|
|
61
|
-
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require('node:child_process');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
|
|
7
|
+
function packageDir(name) {
|
|
8
|
+
return path.dirname(require.resolve(`${name}/package.json`, { paths: [process.cwd(), __dirname] }));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function run(command, args, cwd) {
|
|
12
|
+
const result = spawnSync(command, args, { cwd, stdio: 'inherit', shell: false });
|
|
13
|
+
if (result.status !== 0) process.exit(result.status || 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function verify(hnswDir) {
|
|
17
|
+
const hnsw = require(path.join(hnswDir, 'lib/index.js'));
|
|
18
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hnsw-doctor-'));
|
|
19
|
+
try {
|
|
20
|
+
const indexPath = path.join(dir, 'index.bin');
|
|
21
|
+
const index = new hnsw.HierarchicalNSW('cosine', 2);
|
|
22
|
+
index.initIndex(10, 16, 200, 100, true);
|
|
23
|
+
index.addPoint([1, 0], 1);
|
|
24
|
+
index.addPoint([0, 1], 2);
|
|
25
|
+
const result = index.searchKnn([1, 0], 1);
|
|
26
|
+
index.writeIndexSync(indexPath);
|
|
27
|
+
const loaded = new hnsw.HierarchicalNSW('cosine', 2);
|
|
28
|
+
loaded.readIndexSync(indexPath, true);
|
|
29
|
+
const loadedResult = loaded.searchKnn([1, 0], 1);
|
|
30
|
+
if (result.neighbors[0] !== 1 || loadedResult.neighbors[0] !== 1) throw new Error('HNSW 检索验证失败');
|
|
31
|
+
} finally {
|
|
32
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const hnswDir = packageDir('hnswlib-node');
|
|
38
|
+
const nodeGypBin = require.resolve('node-gyp/bin/node-gyp.js', { paths: [process.cwd(), __dirname] });
|
|
39
|
+
console.log(`[hnsw] 构建 hnswlib-node native binding: ${hnswDir}`);
|
|
40
|
+
run(process.execPath, [nodeGypBin, 'rebuild'], hnswDir);
|
|
41
|
+
verify(hnswDir);
|
|
42
|
+
console.log('[hnsw] hnswlib-node 安装和运行验证通过');
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('[hnsw] hnswlib-node 安装或运行验证失败。请确认当前平台已安装 native 编译工具链。');
|
|
45
|
+
console.error(error && error.stack ? error.stack : error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { CollectionClient, VectorCollectionInfo, VectorDocument, VectorSearchQuery, VectorSearchResult, VectorStoreInterface } from './types.js';
|
|
2
|
-
interface SearchRow {
|
|
3
|
-
id: string;
|
|
4
|
-
content: string;
|
|
5
|
-
metadata_json: string | null;
|
|
6
|
-
distance: number;
|
|
7
|
-
}
|
|
8
|
-
export interface SQLiteVecClientOptions {
|
|
9
|
-
dbPath: string;
|
|
10
|
-
}
|
|
11
|
-
export declare class SQLiteVecClient implements CollectionClient {
|
|
12
|
-
readonly dbPath: string;
|
|
13
|
-
private readonly db;
|
|
14
|
-
constructor(options: SQLiteVecClientOptions);
|
|
15
|
-
getOrCreateCollection(name: string, metadata?: Record<string, unknown>): Promise<VectorCollectionInfo>;
|
|
16
|
-
listCollections(): Promise<VectorCollectionInfo[]>;
|
|
17
|
-
deleteCollection(name: string): Promise<void>;
|
|
18
|
-
upsert(collectionName: string, documents: VectorDocument[]): void;
|
|
19
|
-
deleteWhere(collectionName: string, where: Record<string, string | number | boolean>): void;
|
|
20
|
-
deleteByFilePath(collectionName: string, filePath: string): void;
|
|
21
|
-
search(collectionName: string, query: VectorSearchQuery): SearchRow[];
|
|
22
|
-
private getCollection;
|
|
23
|
-
private requireCollection;
|
|
24
|
-
private tableName;
|
|
25
|
-
private parseMetadata;
|
|
26
|
-
private metadataString;
|
|
27
|
-
}
|
|
28
|
-
export declare class SQLiteVecVectorStore implements VectorStoreInterface {
|
|
29
|
-
private readonly client;
|
|
30
|
-
readonly collectionName: string;
|
|
31
|
-
constructor(client: SQLiteVecClient, collectionName: string);
|
|
32
|
-
ensureCollection(metadata?: Record<string, unknown>): Promise<void>;
|
|
33
|
-
upsert(documents: VectorDocument[]): Promise<void>;
|
|
34
|
-
deleteByFilePath(filePath: string): Promise<void>;
|
|
35
|
-
search(query: VectorSearchQuery): Promise<VectorSearchResult[]>;
|
|
36
|
-
private parseDocumentMetadata;
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import Database from 'better-sqlite3';
|
|
2
|
-
import * as crypto from 'node:crypto';
|
|
3
|
-
import * as fs from 'node:fs';
|
|
4
|
-
import * as path from 'node:path';
|
|
5
|
-
import * as sqliteVec from 'sqlite-vec';
|
|
6
|
-
export class SQLiteVecClient {
|
|
7
|
-
dbPath;
|
|
8
|
-
db;
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.dbPath = options.dbPath;
|
|
11
|
-
fs.mkdirSync(path.dirname(options.dbPath), { recursive: true });
|
|
12
|
-
this.db = new Database(options.dbPath);
|
|
13
|
-
this.db.pragma('journal_mode = WAL');
|
|
14
|
-
sqliteVec.load(this.db);
|
|
15
|
-
this.db.exec(`
|
|
16
|
-
CREATE TABLE IF NOT EXISTS vector_collections (
|
|
17
|
-
name TEXT PRIMARY KEY,
|
|
18
|
-
table_name TEXT NOT NULL UNIQUE,
|
|
19
|
-
dimension INTEGER NOT NULL,
|
|
20
|
-
metadata_json TEXT,
|
|
21
|
-
created_at INTEGER NOT NULL
|
|
22
|
-
);
|
|
23
|
-
CREATE TABLE IF NOT EXISTS vector_documents (
|
|
24
|
-
rowid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
25
|
-
collection_name TEXT NOT NULL,
|
|
26
|
-
id TEXT NOT NULL,
|
|
27
|
-
content TEXT NOT NULL,
|
|
28
|
-
metadata_json TEXT,
|
|
29
|
-
file_path TEXT,
|
|
30
|
-
vector_rowid INTEGER,
|
|
31
|
-
created_at INTEGER NOT NULL,
|
|
32
|
-
updated_at INTEGER NOT NULL,
|
|
33
|
-
UNIQUE(collection_name, id)
|
|
34
|
-
);
|
|
35
|
-
CREATE INDEX IF NOT EXISTS idx_vector_documents_collection_file ON vector_documents(collection_name, file_path);
|
|
36
|
-
`);
|
|
37
|
-
try {
|
|
38
|
-
this.db.exec('ALTER TABLE vector_documents ADD COLUMN vector_rowid INTEGER');
|
|
39
|
-
}
|
|
40
|
-
catch { /* column already exists */ }
|
|
41
|
-
}
|
|
42
|
-
async getOrCreateCollection(name, metadata = {}) {
|
|
43
|
-
const existing = this.getCollection(name);
|
|
44
|
-
if (existing)
|
|
45
|
-
return { name: existing.name, metadata: this.parseMetadata(existing.metadata_json) };
|
|
46
|
-
const dimension = Number(metadata.embedding_dimension ?? 384);
|
|
47
|
-
const tableName = this.tableName(name);
|
|
48
|
-
this.db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS ${tableName} USING vec0(embedding float[${dimension}])`);
|
|
49
|
-
this.db.prepare(`
|
|
50
|
-
INSERT INTO vector_collections (name, table_name, dimension, metadata_json, created_at)
|
|
51
|
-
VALUES (?, ?, ?, ?, ?)
|
|
52
|
-
`).run(name, tableName, dimension, JSON.stringify(metadata), Date.now());
|
|
53
|
-
return { name, metadata };
|
|
54
|
-
}
|
|
55
|
-
async listCollections() {
|
|
56
|
-
return this.db.prepare('SELECT name, metadata_json FROM vector_collections ORDER BY name').all()
|
|
57
|
-
.map(row => {
|
|
58
|
-
const record = row;
|
|
59
|
-
return { name: record.name, metadata: this.parseMetadata(record.metadata_json) };
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
async deleteCollection(name) {
|
|
63
|
-
const collection = this.getCollection(name);
|
|
64
|
-
if (!collection)
|
|
65
|
-
return;
|
|
66
|
-
this.db.exec(`DROP TABLE IF EXISTS ${collection.table_name}`);
|
|
67
|
-
this.db.prepare('DELETE FROM vector_documents WHERE collection_name = ?').run(name);
|
|
68
|
-
this.db.prepare('DELETE FROM vector_collections WHERE name = ?').run(name);
|
|
69
|
-
}
|
|
70
|
-
upsert(collectionName, documents) {
|
|
71
|
-
if (documents.length === 0)
|
|
72
|
-
return;
|
|
73
|
-
const collection = this.requireCollection(collectionName);
|
|
74
|
-
const deleteVec = this.db.prepare(`DELETE FROM ${collection.table_name} WHERE rowid = ?`);
|
|
75
|
-
const deleteDoc = this.db.prepare('DELETE FROM vector_documents WHERE collection_name = ? AND id = ?');
|
|
76
|
-
const insertDoc = this.db.prepare(`
|
|
77
|
-
INSERT INTO vector_documents (collection_name, id, content, metadata_json, file_path, created_at, updated_at)
|
|
78
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
79
|
-
`);
|
|
80
|
-
const updateVectorRowid = this.db.prepare('UPDATE vector_documents SET vector_rowid = ? WHERE rowid = ?');
|
|
81
|
-
const insertVec = this.db.prepare(`INSERT INTO ${collection.table_name} (embedding) VALUES (vec_f32(?))`);
|
|
82
|
-
const existingRow = this.db.prepare('SELECT rowid, vector_rowid FROM vector_documents WHERE collection_name = ? AND id = ?');
|
|
83
|
-
const transaction = this.db.transaction((items) => {
|
|
84
|
-
for (const document of items) {
|
|
85
|
-
const existing = existingRow.get(collectionName, document.id);
|
|
86
|
-
if (existing?.vector_rowid)
|
|
87
|
-
deleteVec.run(existing.vector_rowid);
|
|
88
|
-
deleteDoc.run(collectionName, document.id);
|
|
89
|
-
const now = Date.now();
|
|
90
|
-
const metadataJson = JSON.stringify(document.metadata);
|
|
91
|
-
const filePath = this.metadataString(document.metadata.file_path);
|
|
92
|
-
const documentResult = insertDoc.run(collectionName, document.id, document.content, metadataJson, filePath, now, now);
|
|
93
|
-
const vectorResult = insertVec.run(JSON.stringify(document.embedding));
|
|
94
|
-
updateVectorRowid.run(Number(vectorResult.lastInsertRowid), Number(documentResult.lastInsertRowid));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
transaction(documents);
|
|
98
|
-
}
|
|
99
|
-
deleteWhere(collectionName, where) {
|
|
100
|
-
if (typeof where.file_path !== 'string')
|
|
101
|
-
return;
|
|
102
|
-
this.deleteByFilePath(collectionName, where.file_path);
|
|
103
|
-
}
|
|
104
|
-
deleteByFilePath(collectionName, filePath) {
|
|
105
|
-
const collection = this.getCollection(collectionName);
|
|
106
|
-
if (!collection)
|
|
107
|
-
return;
|
|
108
|
-
const rows = this.db.prepare('SELECT vector_rowid FROM vector_documents WHERE collection_name = ? AND file_path = ?').all(collectionName, filePath);
|
|
109
|
-
const deleteVec = this.db.prepare(`DELETE FROM ${collection.table_name} WHERE rowid = ?`);
|
|
110
|
-
const deleteDocs = this.db.prepare('DELETE FROM vector_documents WHERE collection_name = ? AND file_path = ?');
|
|
111
|
-
const transaction = this.db.transaction(() => {
|
|
112
|
-
for (const row of rows) {
|
|
113
|
-
if (row.vector_rowid)
|
|
114
|
-
deleteVec.run(row.vector_rowid);
|
|
115
|
-
}
|
|
116
|
-
deleteDocs.run(collectionName, filePath);
|
|
117
|
-
});
|
|
118
|
-
transaction();
|
|
119
|
-
}
|
|
120
|
-
search(collectionName, query) {
|
|
121
|
-
const collection = this.getCollection(collectionName);
|
|
122
|
-
if (!collection)
|
|
123
|
-
return [];
|
|
124
|
-
const filePath = query.where?.file_path;
|
|
125
|
-
if (typeof filePath === 'string') {
|
|
126
|
-
return this.db.prepare(`
|
|
127
|
-
SELECT d.id, d.content, d.metadata_json, v.distance
|
|
128
|
-
FROM (
|
|
129
|
-
SELECT rowid, distance
|
|
130
|
-
FROM ${collection.table_name}
|
|
131
|
-
WHERE embedding MATCH vec_f32(?) AND k = ?
|
|
132
|
-
) v
|
|
133
|
-
JOIN vector_documents d ON d.vector_rowid = v.rowid
|
|
134
|
-
WHERE d.file_path = ?
|
|
135
|
-
ORDER BY v.distance
|
|
136
|
-
`).all(JSON.stringify(query.queryEmbedding), query.topK, filePath);
|
|
137
|
-
}
|
|
138
|
-
return this.db.prepare(`
|
|
139
|
-
SELECT d.id, d.content, d.metadata_json, v.distance
|
|
140
|
-
FROM (
|
|
141
|
-
SELECT rowid, distance
|
|
142
|
-
FROM ${collection.table_name}
|
|
143
|
-
WHERE embedding MATCH vec_f32(?) AND k = ?
|
|
144
|
-
) v
|
|
145
|
-
JOIN vector_documents d ON d.vector_rowid = v.rowid
|
|
146
|
-
ORDER BY v.distance
|
|
147
|
-
`).all(JSON.stringify(query.queryEmbedding), query.topK);
|
|
148
|
-
}
|
|
149
|
-
getCollection(name) {
|
|
150
|
-
return this.db.prepare('SELECT name, table_name, dimension, metadata_json FROM vector_collections WHERE name = ?').get(name);
|
|
151
|
-
}
|
|
152
|
-
requireCollection(name) {
|
|
153
|
-
const collection = this.getCollection(name);
|
|
154
|
-
if (!collection)
|
|
155
|
-
throw new Error(`SQLite vec collection not found: ${name}`);
|
|
156
|
-
return collection;
|
|
157
|
-
}
|
|
158
|
-
tableName(collectionName) {
|
|
159
|
-
const hash = crypto.createHash('sha256').update(collectionName).digest('hex').slice(0, 16);
|
|
160
|
-
return `vec_${hash}`;
|
|
161
|
-
}
|
|
162
|
-
parseMetadata(metadataJson) {
|
|
163
|
-
if (!metadataJson)
|
|
164
|
-
return undefined;
|
|
165
|
-
return JSON.parse(metadataJson);
|
|
166
|
-
}
|
|
167
|
-
metadataString(value) {
|
|
168
|
-
return typeof value === 'string' ? value : null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
export class SQLiteVecVectorStore {
|
|
172
|
-
client;
|
|
173
|
-
collectionName;
|
|
174
|
-
constructor(client, collectionName) {
|
|
175
|
-
this.client = client;
|
|
176
|
-
this.collectionName = collectionName;
|
|
177
|
-
}
|
|
178
|
-
async ensureCollection(metadata) {
|
|
179
|
-
await this.client.getOrCreateCollection(this.collectionName, metadata);
|
|
180
|
-
}
|
|
181
|
-
async upsert(documents) {
|
|
182
|
-
this.client.upsert(this.collectionName, documents);
|
|
183
|
-
}
|
|
184
|
-
async deleteByFilePath(filePath) {
|
|
185
|
-
this.client.deleteByFilePath(this.collectionName, filePath);
|
|
186
|
-
}
|
|
187
|
-
async search(query) {
|
|
188
|
-
return this.client.search(this.collectionName, query).map(row => ({
|
|
189
|
-
collection: this.collectionName,
|
|
190
|
-
score: 1 / (1 + Number(row.distance ?? 0)),
|
|
191
|
-
document: {
|
|
192
|
-
id: row.id,
|
|
193
|
-
content: row.content,
|
|
194
|
-
metadata: this.parseDocumentMetadata(row.metadata_json),
|
|
195
|
-
},
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
parseDocumentMetadata(metadataJson) {
|
|
199
|
-
if (!metadataJson)
|
|
200
|
-
return {};
|
|
201
|
-
return JSON.parse(metadataJson);
|
|
202
|
-
}
|
|
203
|
-
}
|