@wazootech/worlds-cloudflare 0.15.8 → 0.15.9

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.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
2
2
  import { WorldsSdk } from "@wazootech/worlds-sdk";
3
- import { a as createD1SearchIndexRebuilder, c as emptyVectorSyncReport, d as recordVectorSyncError, f as vectorSyncSucceeded, h as sanitizeFtsQuery, i as CloudflareSearchIndex, l as logVectorSyncDrift, m as RRF_REFERENCE_CONSTANT, n as buildSearchResultId, o as rebuildD1SearchIndexFromQuads, p as D1SearchQueryBuilder, r as D1SearchIndexProjector, s as D1VectorSync, t as buildChunkFtsValue, u as mergeVectorSyncReports } from "./search-index-DVbbsc3z.js";
3
+ import { a as createD1SearchIndexRebuilder, c as emptyVectorSyncReport, d as recordVectorSyncError, f as vectorSyncSucceeded, h as sanitizeFtsQuery, i as CloudflareSearchIndex, l as logVectorSyncDrift, m as RRF_REFERENCE_CONSTANT, n as buildSearchResultId, o as rebuildD1SearchIndexFromQuads, p as D1SearchQueryBuilder, r as D1SearchIndexProjector, s as D1VectorSync, t as buildChunkFtsValue, u as mergeVectorSyncReports } from "./search-index-_yyeZAVm.js";
4
4
  import { a as loadAssertedQuads, i as InferenceSizeGuardError, n as D1ProvenanceStore, o as planInference, t as D1QuadStore } from "./quad-store-C1IJEz2D.js";
5
5
  import { a as DEFAULT_D1_MAX_BATCH_WEIGHT, o as d1StatementWeight } from "./project-search-chunks-options-qI9m5FWz.js";
6
6
  import { WazooSparqlEngine } from "@wazootech/sparql-engine";
7
7
  import { RE2JS } from "re2js";
8
- import { i as D1QuadStream, n as assertD1SchemaCompatible, r as checkD1SchemaCompatibility, t as D1RdfjsStore } from "./rdfjs-store-DfmCIuVz.js";
8
+ import { i as D1QuadStream, n as assertD1SchemaCompatible, r as checkD1SchemaCompatibility, t as D1RdfjsStore } from "./rdfjs-store-YJhcJ8eq.js";
9
9
  import { n as validateWorldId, t as D1SchemaBuilder } from "./d1-schema-builder-emxvwyf9.js";
10
10
  import { g as DEFAULT_D1_MAX_WRITE_BATCH_SIZE, h as D1BatchExecutor, m as quadToInsertRow, s as buildDeleteAllDerivedQuads, t as buildBulkInsertQuads, u as buildWipeAllGraphDataStatements } from "./d1-quad-insert-sql-B4ZiZZe8.js";
11
11
  // src/cloudflare/search-index/vector-search/vectorize-provisioning.ts
@@ -168,7 +168,7 @@ var D1TransactionImpl = class {
168
168
  this.inserted.set(quadKey(quad), quad);
169
169
  }
170
170
  delete(quad) {
171
- if (this.inserted.delete(quadKey(quad))) return;
171
+ this.inserted.delete(quadKey(quad));
172
172
  this.deleted.set(quadKey(quad), quad);
173
173
  }
174
174
  commit() {
@@ -1 +1 @@
1
- export { i as D1QuadStream, t as D1RdfjsStore } from "./rdfjs-store-DfmCIuVz.js";
1
+ export { i as D1QuadStream, t as D1RdfjsStore } from "./rdfjs-store-YJhcJ8eq.js";
@@ -2,7 +2,8 @@ import { RRF_FUSION_K, buildChunkFtsValue, buildIncludeExcludeFilterClauses, bui
2
2
  import { normalizeRrfScore } from "@wazootech/worlds-sdk/search-index";
3
3
  import { _ as effectiveLookupChunkSize } from "./d1-quad-insert-sql-B4ZiZZe8.js";
4
4
  import { i as createD1CommitDriver, n as toProjectionOptions, r as vectorSyncEnabled, s as createD1CommitDialect, t as isFullRebuild } from "./project-search-chunks-options-qI9m5FWz.js";
5
- import { hashQuads } from "@wazootech/worlds-sdk/quad-store";
5
+ import { filterQuads, hashQuads } from "@wazootech/worlds-sdk/quad-store";
6
+ import { DataFactory } from "@wazootech/sparql-engine/data-model";
6
7
  // src/cloudflare/search-index/d1-world-scoped-fts.ts
7
8
  /** RRF constant shared with the generic keyword plan (1 / (60 + rank)). */
8
9
  const RRF_K = 60;
@@ -489,6 +490,20 @@ function hitToSearchResult(hit) {
489
490
  function clampCosine(score) {
490
491
  return Math.max(0, Math.min(1, score));
491
492
  }
493
+ // src/cloudflare/search-index/filter-vector-hits.ts
494
+ const { literal, namedNode, quad } = DataFactory;
495
+ /**
496
+ * filterVectorHits keeps the hits that match a request's include and exclude,
497
+ * in order, with the meaning they have for stored facts and for the keyword
498
+ * query. The vector index can only filter on `world_id`, so this runs after its
499
+ * query. The index then returns its nearest `candidateCount` hits of the whole
500
+ * world, and a narrow filter can leave fewer vector results than that. The
501
+ * keyword query filters in SQL and is not affected.
502
+ */
503
+ function filterVectorHits(hits, filter) {
504
+ const matches = filterQuads(filter);
505
+ return hits.filter(({ metadata }) => matches(quad(namedNode(metadata?.subject ?? ""), namedNode(metadata?.predicate ?? ""), literal(metadata?.value ?? ""), namedNode(metadata?.graph ?? ""))));
506
+ }
492
507
  // src/cloudflare/search-index/cloudflare-search-index.ts
493
508
  /**
494
509
  * CloudflareSearchIndex implements the query pathway over D1's FTS5
@@ -540,10 +555,10 @@ var CloudflareSearchIndex = class {
540
555
  if (this.options.embeddingService && this.options.vectorSearch) try {
541
556
  const embedded = await this.options.embeddingService.embed([request.query]);
542
557
  const queryVector = embedded[0] ? new Float32Array(embedded[0]) : void 0;
543
- if (queryVector) vectorHits = await this.options.vectorSearch.query(Array.from(queryVector), {
558
+ if (queryVector) vectorHits = filterVectorHits(await this.options.vectorSearch.query(Array.from(queryVector), {
544
559
  topK: candidateCount,
545
560
  ...this.options.worldId ? { filter: { world_id: this.options.worldId } } : {}
546
- });
561
+ }), request);
547
562
  } catch (error) {
548
563
  console.warn("[Search Warning] vector query failed; falling back to keyword-only", error);
549
564
  }
@@ -1 +1 @@
1
- export { i as CloudflareSearchIndex, r as D1SearchIndexProjector, p as D1SearchQueryBuilder, s as D1VectorSync, m as RRF_REFERENCE_CONSTANT, t as buildChunkFtsValue, n as buildSearchResultId, a as createD1SearchIndexRebuilder, c as emptyVectorSyncReport, l as logVectorSyncDrift, u as mergeVectorSyncReports, o as rebuildD1SearchIndexFromQuads, d as recordVectorSyncError, h as sanitizeFtsQuery, f as vectorSyncSucceeded } from "./search-index-DVbbsc3z.js";
1
+ export { i as CloudflareSearchIndex, r as D1SearchIndexProjector, p as D1SearchQueryBuilder, s as D1VectorSync, m as RRF_REFERENCE_CONSTANT, t as buildChunkFtsValue, n as buildSearchResultId, a as createD1SearchIndexRebuilder, c as emptyVectorSyncReport, l as logVectorSyncDrift, u as mergeVectorSyncReports, o as rebuildD1SearchIndexFromQuads, d as recordVectorSyncError, h as sanitizeFtsQuery, f as vectorSyncSucceeded } from "./search-index-_yyeZAVm.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazootech/worlds-cloudflare",
3
- "version": "0.15.8",
3
+ "version": "0.15.9",
4
4
  "description": "Store a Worlds knowledge graph in Cloudflare D1, with keyword search, optional Vectorize search, SPARQL and provenance. Made for Cloudflare Workers.",
5
5
  "keywords": [
6
6
  "wazoo",
@@ -72,9 +72,9 @@
72
72
  "@langchain/textsplitters": "^1.0.1",
73
73
  "@rdfjs/types": "^2.0.1",
74
74
  "@wazootech/reasoner": "^0.4.4",
75
- "@wazootech/sparql-engine": "^0.5.11",
76
- "@wazootech/worlds-sdk": "^0.11.5",
77
- "@wazootech/worlds-sqlite": "^0.8.4",
75
+ "@wazootech/sparql-engine": "^0.5.12",
76
+ "@wazootech/worlds-sdk": "^0.11.6",
77
+ "@wazootech/worlds-sqlite": "^0.8.5",
78
78
  "re2js": "2.10.0"
79
79
  },
80
80
  "devDependencies": {