nano-brain 2026.7.3 → 2026.7.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/embeddings.ts +40 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nano-brain",
3
- "version": "2026.7.3",
3
+ "version": "2026.7.4",
4
4
  "description": "Persistent memory and code intelligence for AI coding agents. Local MCP server with self-learning hybrid search (BM25 + vector + knowledge graph + LLM reranking), automatic session ingestion, codebase indexing, and 22 tools. Learns your preferences over time. Works with OpenCode, Claude, Cursor, Windsurf, and any MCP client.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/embeddings.ts CHANGED
@@ -150,13 +150,13 @@ class OllamaEmbeddingProvider implements EmbeddingProvider {
150
150
  };
151
151
  }
152
152
 
153
- async embedBatch(texts: string[]): Promise<EmbeddingResult[]> {
153
+ private async _sendBatch(inputs: string[]): Promise<EmbeddingResult[]> {
154
154
  const response = await fetch(`${this.url}/api/embed`, {
155
155
  method: 'POST',
156
156
  headers: { 'Content-Type': 'application/json' },
157
157
  body: JSON.stringify({
158
158
  model: this.model,
159
- input: texts.map(t => this.truncate(t)),
159
+ input: inputs.map(t => this.truncate(t)),
160
160
  }),
161
161
  signal: AbortSignal.timeout(180000),
162
162
  });
@@ -176,6 +176,44 @@ class OllamaEmbeddingProvider implements EmbeddingProvider {
176
176
  }));
177
177
  }
178
178
 
179
+ async embedBatch(texts: string[]): Promise<EmbeddingResult[]> {
180
+ const MAX_CHARS_PER_BATCH = 100_000; // ~25K tokens safety margin
181
+ const MAX_ITEMS_PER_BATCH = 50; // Also limit item count
182
+ const results: EmbeddingResult[] = [];
183
+
184
+ // Split into sub-batches by cumulative character count
185
+ let currentBatch: string[] = [];
186
+ let currentChars = 0;
187
+ let batchCount = 0;
188
+
189
+ for (const text of texts) {
190
+ if (currentBatch.length > 0 &&
191
+ (currentChars + text.length > MAX_CHARS_PER_BATCH ||
192
+ currentBatch.length >= MAX_ITEMS_PER_BATCH)) {
193
+ batchCount++;
194
+ const embeddings = await this._sendBatch(currentBatch);
195
+ results.push(...embeddings);
196
+ currentBatch = [];
197
+ currentChars = 0;
198
+ }
199
+ currentBatch.push(text);
200
+ currentChars += text.length;
201
+ }
202
+
203
+ // Send remaining
204
+ if (currentBatch.length > 0) {
205
+ batchCount++;
206
+ const embeddings = await this._sendBatch(currentBatch);
207
+ results.push(...embeddings);
208
+ }
209
+
210
+ if (batchCount > 1) {
211
+ log('embed', `Ollama sub-batching: ${texts.length} items into ${batchCount} batches`);
212
+ }
213
+
214
+ return results;
215
+ }
216
+
179
217
  getDimensions(): number {
180
218
  return this.dimensions;
181
219
  }