@semiont/make-meaning 0.5.9 → 0.5.10

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.
@@ -1,8 +1,7 @@
1
- import { createTomlConfigLoader, accessToken, baseUrl as baseUrl$1, burstBuffer, errField, resourceId, textExtractionOf, decodeRepresentation, getTargetSelector, getExactText, annotationId, getPrimaryMediaType, getPrimaryRepresentation } from '@semiont/core';
1
+ import { createTomlConfigLoader, accessToken, baseUrl as baseUrl$1, burstBuffer, errField, resourceId, textExtractionOf, decodeRepresentation, busRequest, getResourceEntityTypes, getTargetSelector, getExactText, annotationId, getPrimaryMediaType, getPrimaryRepresentation } from '@semiont/core';
2
2
  import { calculateChecksum } from '@semiont/content';
3
3
  import { createEmbeddingProvider, createVectorStore, chunkText } from '@semiont/vectors';
4
4
  import { registerVectorIndexSizeProvider, withActorSpan } from '@semiont/observability';
5
- import { busRequest } from '@semiont/sdk';
6
5
  import { HttpTransport, HttpContentTransport } from '@semiont/http-transport';
7
6
  import { createServer } from 'http';
8
7
  import { existsSync, readFileSync } from 'fs';
@@ -9998,6 +9997,23 @@ var Smelter = class _Smelter {
9998
9997
  return null;
9999
9998
  }
10000
9999
  }
10000
+ /**
10001
+ * Read a resource's current entity types from the materialized view — the
10002
+ * authoritative source, updated before the EventBus fires to consumers — so
10003
+ * its vectors carry the discriminator `searchResources` filters on (e.g.
10004
+ * exclude `['Question']`). One read on every embed path, mirroring how the
10005
+ * smelter already reads current content and annotations; a failed read
10006
+ * propagates to the pipeline's per-resource error handler (reconcile heals),
10007
+ * rather than silently stamping `[]` and letting the resource leak into recall.
10008
+ */
10009
+ async resolveEntityTypes(resourceId) {
10010
+ const { resource } = await busRequest(
10011
+ this.bus,
10012
+ "browse:resource-requested",
10013
+ { resourceId }
10014
+ );
10015
+ return getResourceEntityTypes(resource);
10016
+ }
10001
10017
  async embedResource(event, logMessage) {
10002
10018
  const rid = event.resourceId;
10003
10019
  if (!rid) return;
@@ -10005,13 +10021,14 @@ var Smelter = class _Smelter {
10005
10021
  if (!fetched) return;
10006
10022
  const chunks = chunkText(fetched.text, this.chunkingConfig);
10007
10023
  if (chunks.length === 0) return;
10024
+ const entityTypes = await this.resolveEntityTypes(rid);
10008
10025
  const embeddings = await this.embeddingProvider.embedBatch(chunks);
10009
10026
  const embeddingChunks = chunks.map((t, i) => ({
10010
10027
  chunkIndex: i,
10011
10028
  text: t,
10012
10029
  embedding: embeddings[i]
10013
10030
  }));
10014
- await this.vectorStore.upsertResourceVectors(resourceId(rid), embeddingChunks, fetched.checksum);
10031
+ await this.vectorStore.upsertResourceVectors(resourceId(rid), embeddingChunks, fetched.checksum, entityTypes);
10015
10032
  this.logger.info(logMessage, { resourceId: rid, chunks: chunks.length });
10016
10033
  }
10017
10034
  async handleResourceArchived(event) {
@@ -10062,19 +10079,20 @@ var Smelter = class _Smelter {
10062
10079
  if (!fetched) continue;
10063
10080
  const chunks = chunkText(fetched.text, this.chunkingConfig);
10064
10081
  if (chunks.length === 0) continue;
10065
- resourceData.push({ rid: resourceId(rid), chunks, checksum: fetched.checksum });
10082
+ const entityTypes = await this.resolveEntityTypes(rid);
10083
+ resourceData.push({ rid: resourceId(rid), chunks, checksum: fetched.checksum, entityTypes });
10066
10084
  allChunks.push(...chunks);
10067
10085
  }
10068
10086
  if (allChunks.length === 0) return events.length;
10069
10087
  const allEmbeddings = await this.embeddingProvider.embedBatch(allChunks);
10070
10088
  let offset = 0;
10071
- for (const { rid, chunks, checksum } of resourceData) {
10089
+ for (const { rid, chunks, checksum, entityTypes } of resourceData) {
10072
10090
  const embeddingChunks = chunks.map((t, i) => ({
10073
10091
  chunkIndex: i,
10074
10092
  text: t,
10075
10093
  embedding: allEmbeddings[offset + i]
10076
10094
  }));
10077
- await this.vectorStore.upsertResourceVectors(rid, embeddingChunks, checksum);
10095
+ await this.vectorStore.upsertResourceVectors(rid, embeddingChunks, checksum, entityTypes);
10078
10096
  this.logger.info("Batch-indexed resource", { resourceId: String(rid), chunks: chunks.length });
10079
10097
  offset += chunks.length;
10080
10098
  }
@@ -10181,9 +10199,7 @@ var Smelter = class _Smelter {
10181
10199
  const { annotations } = await busRequest(
10182
10200
  this.bus,
10183
10201
  "browse:annotations-requested",
10184
- { resourceId: rid },
10185
- "browse:annotations-result",
10186
- "browse:annotations-failed"
10202
+ { resourceId: rid }
10187
10203
  );
10188
10204
  for (const annotation of annotations) {
10189
10205
  const exactText = getExactText(getTargetSelector(annotation.target));
@@ -10241,9 +10257,7 @@ var Smelter = class _Smelter {
10241
10257
  const page = await busRequest(
10242
10258
  this.bus,
10243
10259
  "browse:resources-requested",
10244
- { archived: false, offset: all.length, limit: _Smelter.RECONCILE_PAGE_SIZE },
10245
- "browse:resources-result",
10246
- "browse:resources-failed"
10260
+ { archived: false, offset: all.length, limit: _Smelter.RECONCILE_PAGE_SIZE }
10247
10261
  );
10248
10262
  all.push(...page.resources);
10249
10263
  if (page.resources.length === 0 || all.length >= page.total) return all;