xiaozuoassistant 0.2.28 → 0.2.29

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,13 +26,25 @@ 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
+ }
29
41
  if (!tableNames.includes('memories')) {
30
42
  // Create table with dummy data to define schema, then delete it
31
43
  // LanceDB schema inference is based on data
32
44
  const dummyData = [{
33
45
  id: 'init',
34
46
  text: 'init',
35
- vector: Array(1536).fill(0), // OpenAI embedding dimension
47
+ vector: Array(vectorDim).fill(0),
36
48
  metadata: { type: 'recent', timestamp: Date.now(), sessionId: 'init', tags: '' }
37
49
  }];
38
50
  this.table = await this.db.createTable('memories', dummyData);
@@ -50,12 +62,10 @@ export class VectorMemory {
50
62
  async getEmbedding(text) {
51
63
  if (!this.openai) {
52
64
  console.warn('OpenAI client not initialized (missing API Key), skipping embedding.');
53
- return Array(1536).fill(0);
65
+ return []; // Return empty instead of zero array
54
66
  }
55
67
  try {
56
68
  // Use OpenAI compatible embedding endpoint
57
- // Note: Some compatible providers might use different models/dimensions.
58
- // Default to text-embedding-ada-002 or similar standard.
59
69
  const model = config.llm.embeddingModel || 'text-embedding-ada-002';
60
70
  const response = await this.openai.embeddings.create({
61
71
  model: model,
@@ -65,9 +75,7 @@ export class VectorMemory {
65
75
  }
66
76
  catch (error) {
67
77
  console.error('Embedding failed:', error);
68
- // Fallback: return zero vector or throw?
69
- // For MVP robustness, return zeros if embedding fails (search won't work but app won't crash)
70
- return Array(1536).fill(0);
78
+ return []; // Return empty instead of zero array to trigger upstream handling
71
79
  }
72
80
  }
73
81
  async addMemory(text, type, metadata = {}) {
@@ -76,6 +84,10 @@ export class VectorMemory {
76
84
  if (!this.table)
77
85
  return; // DB failed to init
78
86
  const vector = await this.getEmbedding(text);
87
+ if (!vector || vector.length === 0) {
88
+ console.error('Failed to get valid embedding, skipping memory addition.');
89
+ return;
90
+ }
79
91
  const memory = {
80
92
  id: Math.random().toString(36).substring(7),
81
93
  text,
@@ -99,6 +111,10 @@ export class VectorMemory {
99
111
  if (!this.table)
100
112
  return [];
101
113
  const vector = await this.getEmbedding(query);
114
+ if (!vector || vector.length === 0) {
115
+ console.error('Failed to get valid embedding for query, skipping search.');
116
+ return [];
117
+ }
102
118
  // Check if table supports search
103
119
  if (this.table.search) {
104
120
  let search = this.table.search(vector).limit(limit);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
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",