xiaozuoassistant 0.2.31 → 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.
@@ -57,10 +57,43 @@ export class VectorMemory {
57
57
  const testVector = await this.getEmbedding('init');
58
58
  if (testVector && testVector.length > 0) {
59
59
  // 读取表中的一行来获取表的维度
60
- const sample = await this.table.search(Array(testVector.length).fill(0)).limit(1).execute().catch(() => null);
61
- if (sample && sample.length > 0 && sample[0].vector.length !== testVector.length) {
62
- console.error(`[VectorMemory] CRITICAL: Existing database dimension (${sample[0].vector.length}) does not match current model dimension (${testVector.length}).`);
63
- console.error(`[VectorMemory] You MUST delete the vector database directory manually to reset it.`);
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
+ }
64
97
  }
65
98
  }
66
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.31",
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",