@plur-ai/core 0.2.5 → 0.2.7

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.
package/dist/index.d.ts CHANGED
@@ -769,8 +769,11 @@ declare class Plur {
769
769
  private _filterEngrams;
770
770
  /** Reactivate accessed engrams (bump retrieval strength, frequency, last_accessed) */
771
771
  private _reactivateResults;
772
- /** Scored injection within token budget. Returns formatted strings. */
772
+ /** Scored injection within token budget (BM25 only). Returns formatted strings. */
773
773
  inject(task: string, options?: InjectOptions): InjectionResult;
774
+ /** Scored injection with embedding boost when available. Falls back to BM25 if embeddings not installed. */
775
+ injectHybrid(task: string, options?: InjectOptions): Promise<InjectionResult>;
776
+ private _formatInjection;
774
777
  /** Update feedback_signals and adjust retrieval_strength. */
775
778
  feedback(id: string, signal: 'positive' | 'negative' | 'neutral'): void;
776
779
  /** Set engram status to 'retired'. */
package/dist/index.js CHANGED
@@ -511,7 +511,7 @@ function fillTokenBudget(scored, maxTokens) {
511
511
  }
512
512
  return { selected: result, tokens_used: tokensUsed };
513
513
  }
514
- function selectAndSpread(ctx, personalEngrams, packs, config) {
514
+ function selectAndSpread(ctx, personalEngrams, packs, config, embeddingBoosts) {
515
515
  const spreadCap = config?.spread_cap ?? 3;
516
516
  const spreadBudget = config?.spread_budget ?? 480;
517
517
  const promptLower = ctx.prompt.toLowerCase();
@@ -523,7 +523,13 @@ function selectAndSpread(ctx, personalEngrams, packs, config) {
523
523
  for (const engram of personalEngrams) {
524
524
  if (engram.status !== "active") continue;
525
525
  engramMap.set(engram.id, engram);
526
- const raw = scoreEngram(engram, promptLower, promptWords, [], ctx.scope, false);
526
+ let raw = scoreEngram(engram, promptLower, promptWords, [], ctx.scope, false);
527
+ const embBoost = embeddingBoosts?.get(engram.id) ?? 0;
528
+ if (raw === 0 && embBoost > 0.3) {
529
+ raw = embBoost * 2;
530
+ } else if (raw > 0 && embBoost > 0) {
531
+ raw += embBoost;
532
+ }
527
533
  if (raw > 0) {
528
534
  scored.push({ ...engram, keyword_match: raw, raw_score: raw, score: raw });
529
535
  }
@@ -535,7 +541,13 @@ function selectAndSpread(ctx, personalEngrams, packs, config) {
535
541
  for (const engram of pack.engrams) {
536
542
  if (engram.status !== "active") continue;
537
543
  engramMap.set(engram.id, engram);
538
- const raw = scoreEngram(engram, promptLower, promptWords, matchTerms, ctx.scope, true);
544
+ let raw = scoreEngram(engram, promptLower, promptWords, matchTerms, ctx.scope, true);
545
+ const embBoost = embeddingBoosts?.get(engram.id) ?? 0;
546
+ if (raw === 0 && embBoost > 0.3) {
547
+ raw = embBoost * 2;
548
+ } else if (raw > 0 && embBoost > 0) {
549
+ raw += embBoost;
550
+ }
539
551
  if (raw > 0) {
540
552
  scored.push({ ...engram, keyword_match: raw, raw_score: raw, score: raw });
541
553
  }
@@ -1346,8 +1358,27 @@ var Plur = class {
1346
1358
  }
1347
1359
  if (modified) saveEngrams(this.paths.engrams, allEngrams);
1348
1360
  }
1349
- /** Scored injection within token budget. Returns formatted strings. */
1361
+ /** Scored injection within token budget (BM25 only). Returns formatted strings. */
1350
1362
  inject(task, options) {
1363
+ return this._formatInjection(task, options);
1364
+ }
1365
+ /** Scored injection with embedding boost when available. Falls back to BM25 if embeddings not installed. */
1366
+ async injectHybrid(task, options) {
1367
+ let embeddingBoosts;
1368
+ try {
1369
+ const engrams = loadEngrams(this.paths.engrams).filter((e) => e.status === "active");
1370
+ const results = await embeddingSearch(engrams, task, engrams.length, this.paths.root);
1371
+ if (results.length > 0) {
1372
+ embeddingBoosts = /* @__PURE__ */ new Map();
1373
+ for (let i = 0; i < results.length; i++) {
1374
+ embeddingBoosts.set(results[i].id, 1 / (1 + i * 0.1));
1375
+ }
1376
+ }
1377
+ } catch {
1378
+ }
1379
+ return this._formatInjection(task, options, embeddingBoosts);
1380
+ }
1381
+ _formatInjection(task, options, embeddingBoosts) {
1351
1382
  const engrams = loadEngrams(this.paths.engrams);
1352
1383
  const packs = loadAllPacks(this.paths.packs);
1353
1384
  const budget = options?.budget ?? this.config.injection_budget ?? 2e3;
@@ -1362,7 +1393,8 @@ var Plur = class {
1362
1393
  {
1363
1394
  spread_cap: this.config.injection?.spread_cap,
1364
1395
  spread_budget: this.config.injection?.spread_budget
1365
- }
1396
+ },
1397
+ embeddingBoosts
1366
1398
  );
1367
1399
  const formatEngrams = (wires) => {
1368
1400
  if (wires.length === 0) return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plur-ai/core",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",