@soulcraft/brainy 5.1.0 → 5.1.1

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/dist/brainy.js +13 -6
  2. package/package.json +1 -1
package/dist/brainy.js CHANGED
@@ -511,15 +511,18 @@ export class Brainy {
511
511
  if (!existing) {
512
512
  throw new Error(`Entity ${params.id} not found`);
513
513
  }
514
- // Update vector if data changed
514
+ // Update vector if data changed OR if type changed (need to re-index with new type)
515
515
  let vector = existing.vector;
516
- if (params.data) {
517
- vector = params.vector || (await this.embed(params.data));
516
+ const newType = params.type || existing.type;
517
+ if (params.data || params.type) {
518
+ if (params.data) {
519
+ vector = params.vector || (await this.embed(params.data));
520
+ }
518
521
  // Update in index (remove and re-add since no update method)
519
522
  // Phase 2: pass type for TypeAwareHNSWIndex
520
523
  if (this.index instanceof TypeAwareHNSWIndex) {
521
524
  await this.index.removeItem(params.id, existing.type);
522
- await this.index.addItem({ id: params.id, vector }, existing.type);
525
+ await this.index.addItem({ id: params.id, vector }, newType); // v5.1.0: use new type
523
526
  }
524
527
  else {
525
528
  await this.index.removeItem(params.id);
@@ -549,14 +552,18 @@ export class Brainy {
549
552
  ...(params.confidence === undefined && existing.confidence !== undefined && { confidence: existing.confidence }),
550
553
  ...(params.weight === undefined && existing.weight !== undefined && { weight: existing.weight })
551
554
  };
552
- // v4.0.0: Save vector and metadata separately
555
+ // v4.0.0: Save metadata FIRST (v5.1.0 fix: updates type cache for TypeAwareStorage)
556
+ // v5.1.0: saveNounMetadata must be called before saveNoun so that the type cache
557
+ // is updated before determining the shard path. Otherwise type changes cause
558
+ // entities to be saved in the wrong shard and become unfindable.
559
+ await this.storage.saveNounMetadata(params.id, updatedMetadata);
560
+ // Then save vector (will use updated type cache)
553
561
  await this.storage.saveNoun({
554
562
  id: params.id,
555
563
  vector,
556
564
  connections: new Map(),
557
565
  level: 0
558
566
  });
559
- await this.storage.saveNounMetadata(params.id, updatedMetadata);
560
567
  // v4.8.0: Build entity structure for metadata index (with top-level fields)
561
568
  const entityForIndexing = {
562
569
  id: params.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",