xiaozuoassistant 0.2.29 → 0.2.30

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.
@@ -26,21 +26,20 @@ export class VectorMemory {
26
26
  this.db = await lancedb.connect(VECTOR_DB_DIR);
27
27
  // Ensure table exists
28
28
  const tableNames = await this.db.tableNames();
29
- let vectorDim = 1536; // Default to text-embedding-ada-002 dimension
30
- // Determine dimension based on configured model
31
- if (config.llm.embeddingModel === 'text-embedding-v1' || config.llm.embeddingModel === 'text-embedding-v2' || config.llm.embeddingModel === 'text-embedding-v3') {
32
- // Aliyun / Dashscope embedding dimension is 1536
33
- vectorDim = 1536;
34
- }
35
- else if (config.llm.embeddingModel === 'text-embedding-3-small') {
36
- vectorDim = 1536;
37
- }
38
- else if (config.llm.embeddingModel === 'text-embedding-3-large') {
39
- vectorDim = 3072;
40
- }
41
29
  if (!tableNames.includes('memories')) {
42
30
  // Create table with dummy data to define schema, then delete it
43
31
  // LanceDB schema inference is based on data
32
+ let vectorDim = 1536; // Fallback default
33
+ // 动态探测向量维度:通过调用一次真实的 embedding API,获取准确的维度
34
+ console.log(`[VectorMemory] Detecting embedding dimension for model: ${config.llm.embeddingModel || 'default'}...`);
35
+ const testVector = await this.getEmbedding('init');
36
+ if (testVector && testVector.length > 0) {
37
+ vectorDim = testVector.length;
38
+ console.log(`[VectorMemory] Detected actual embedding dimension: ${vectorDim}`);
39
+ }
40
+ else {
41
+ console.warn(`[VectorMemory] Failed to detect dimension, falling back to ${vectorDim}`);
42
+ }
44
43
  const dummyData = [{
45
44
  id: 'init',
46
45
  text: 'init',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.29",
3
+ "version": "0.2.30",
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",