Skip to content
This repository was archived by the owner on Oct 14, 2026. It is now read-only.

Commit 387ffa4

Browse files
author
Tanase Butcaru
committed
fix(data-access): document the semantic-index helpers in the README (LLMO-7445)
1 parent ddf739d commit 387ffa4

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • packages/spacecat-shared-data-access

‎packages/spacecat-shared-data-access/README.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,40 @@ const matches = await lookupEntityIdsByUrl(postgrestClient, {
140140

141141
See the package `CLAUDE.md` ("URL Index") for the canonicalization, single-writer, and site-scoping contracts.
142142

143+
## Semantic Index
144+
145+
For the topic vector index (`opportunity_semantic_embedding`) and the global query-embedding cache (`semantic_query_embedding`), use the shared helpers so the writer and reader share one text normalization and one storage path. They store and read pre-embedded vectors; embedding is the caller's job (e.g. `AzureEmbeddingClient` from `@adobe/spacecat-shared-gpt-client`).
146+
147+
```js
148+
import {
149+
syncOpportunitySemantic, copyEntityVectors, lookupOpportunitiesByVectors,
150+
getQueryEmbeddings, upsertQueryEmbeddings, touchQueryEmbeddings,
151+
} from '@adobe/spacecat-shared-data-access';
152+
153+
const { postgrestClient } = dataAccess.services;
154+
const scope = { model: 'azure/text-embedding-3-small', dims: 1536 };
155+
156+
// writer (needs the postgrest_writer role): full-replace an opportunity's topic vectors
157+
await syncOpportunitySemantic(postgrestClient, {
158+
siteId, entityId, entityType, sourceType: 'topic', sources: [{ text, vector, ...scope }],
159+
});
160+
161+
// writer: copy an opportunity's vector rows to another opportunity in the same site
162+
await copyEntityVectors(postgrestClient, { siteId, fromEntityId, toEntityId });
163+
164+
// query cache, batched: one entry per text, in input order (null on a miss)
165+
const cached = await getQueryEmbeddings(postgrestClient, { texts, ...scope });
166+
await upsertQueryEmbeddings(postgrestClient, { entries: [{ text, vector }], ...scope });
167+
await touchQueryEmbeddings(postgrestClient, { textHashes, ...scope });
168+
169+
// reader, batched: one best-first list of { entityId, entityType, score } per query vector
170+
const matches = await lookupOpportunitiesByVectors(postgrestClient, {
171+
siteId, sourceType: 'topic', vectors, k: 10, minScore: 0.5, ...scope,
172+
});
173+
```
174+
175+
The batched helpers group their calls internally (search in groups of up to 20 vectors, cache reads/touches in groups of 50 hashes), so callers pass whole lists rather than looping per item.
176+
143177
## Field Mapping Behavior
144178
145179
Public model API remains camelCase while Postgres/PostgREST tables are snake_case.

0 commit comments

Comments
 (0)