xiaozuoassistant 0.2.30 → 0.2.32

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.
@@ -51,6 +51,51 @@ export class VectorMemory {
51
51
  }
52
52
  else {
53
53
  this.table = await this.db.openTable('memories');
54
+ // 如果表存在,且当前模型变更导致查询时维度不匹配,必须提供处理机制或抛出明确错误
55
+ // 为了稳定运行,我们在打开表时验证当前模型的维度是否与表结构匹配
56
+ console.log(`[VectorMemory] Validating embedding dimension for existing table...`);
57
+ const testVector = await this.getEmbedding('init');
58
+ if (testVector && testVector.length > 0) {
59
+ // 读取表中的一行来获取表的维度
60
+ try {
61
+ const sample = await this.table.search(Array(testVector.length).fill(0)).limit(1).execute();
62
+ // 如果没有抛出异常,说明查询成功,但我们需要检查返回的数据结构
63
+ if (sample && sample.length > 0 && sample[0].vector && sample[0].vector.length !== testVector.length) {
64
+ console.error(`[VectorMemory] CRITICAL: Existing database dimension (${sample[0].vector.length}) does not match current model dimension (${testVector.length}).`);
65
+ console.error(`[VectorMemory] You MUST delete the vector database directory manually to reset it.`);
66
+ }
67
+ else if (sample && sample.length === 0) {
68
+ // 表为空,此时如果用错误的维度去 search 可能也会抛错,这在 catch 里处理
69
+ }
70
+ }
71
+ catch (err) {
72
+ // LanceDB 强校验维度,如果维度不匹配,search 执行会直接抛错
73
+ if (err.message && err.message.includes('No vector column found to match with the query vector dimension')) {
74
+ console.error(`[VectorMemory] CRITICAL: Existing database dimension does not match current model dimension (${testVector.length}).`);
75
+ console.error(`[VectorMemory] The system will attempt to recreate the table to resolve this mismatch automatically.`);
76
+ // 尝试自动删除并重建表
77
+ try {
78
+ await this.db.dropTable('memories');
79
+ console.log(`[VectorMemory] Old table dropped successfully.`);
80
+ const dummyData = [{
81
+ id: 'init',
82
+ text: 'init',
83
+ vector: Array(testVector.length).fill(0),
84
+ metadata: { type: 'recent', timestamp: Date.now(), sessionId: 'init', tags: '' }
85
+ }];
86
+ this.table = await this.db.createTable('memories', dummyData);
87
+ console.log(`[VectorMemory] New table created with correct dimension (${testVector.length}).`);
88
+ }
89
+ catch (dropErr) {
90
+ console.error(`[VectorMemory] Failed to automatically drop and recreate table:`, dropErr);
91
+ console.error(`[VectorMemory] You MUST delete the vector database directory manually to reset it.`);
92
+ }
93
+ }
94
+ else {
95
+ console.warn(`[VectorMemory] Validation search encountered a non-dimension error:`, err);
96
+ }
97
+ }
98
+ }
54
99
  }
55
100
  this.isInitialized = true;
56
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "A local-first personal AI assistant with multi-channel support and enhanced memory.",
5
5
  "author": "mantle.lau",
6
6
  "license": "MIT",