Skip to content
SprecherEast
Issue 1497

feat: Related content matched by meaning, with embeddings computed off the server

Back to our plan
Open
enhancementcidependenciesfrontendcmspriority: medium

Problem

Related lists don't know what a page is about (newest posts, next events by date), and an editor can't be expected to link everything by hand. Related content should be matched by meaning, on every content type, with no editor step, and only upcoming events suggested.

Proposed fix

Recommended approach (embeddings computed in CI, compared on the server in code):

  1. Embed off the server. A GitHub Action (on a schedule and after publishes) reads published posts, news, events and the other content types through the site's API, builds one short text per item (title plus summary, about 250 words), and embeds it with a small open model run inside the Action. Only items whose text changed are re-embedded (a content hash decides).
  2. Store the vectors with the content. A small Payload collection (for example content-embeddings): the item (collection and id), model name, a text hash and the vector as a json field (384 numbers, about 4 KB). The Action writes it with an agent token that may only create and update this one collection; it can't edit posts or events. Vectors are never shown or served publicly.
  3. The server only compares. When a post or event page is rendered (it is cached and refreshed on save, no per-request work), a use case in domain/ and use-cases/ loads the page's vector and the candidates' vectors and ranks by cosine similarity in plain TypeScript. At a few hundred items that is under a millisecond of arithmetic and about 1.5 MB of numbers; no database vector feature or extra process is needed. Events are kept only when they are upcoming, checked at read time so nothing goes stale.
  4. Hand-picked wins. Hand-picked items (the sibling issue) come first and are removed from the automatic list; automatic items need a similarity above a cut-off and a small cap, so the block can be empty. The cut-off is tuned on real site content with a short evaluation list recorded in the pull request.
  5. No large language model. If the owner later wants "earlier editions of a recurring event" or finer judgment, that is a separate decision.

Options compared

OptionCost at this site's sizeRuns on the VPS?Library to adoptNotes
A. Small open model in a GitHub Action (recommended): bge-small-en-v1.5 (MIT, 33.4M parameters, 384 dimensions, 512 token limit) or all-MiniLM-L6-v2 (Apache-2.0, 22.7M parameters, 384 dimensions, cuts text at 256 word pieces), run with @huggingface/transformers (Apache-2.0, 16.4k stars)Free (Action minutes only)No@huggingface/transformers, as a CI-only dependency, plus the model weightsNo key, no vendor, content never leaves GitHub. English only, which fits the site
B. Cheap embedding API, OpenAI text-embedding-3-small$0.02 per million tokens: a few hundred items of about 1,000 tokens is roughly $0.01 for a full re-embed, and a new item costs a fraction of a cent (my estimate from the listed price)NoNone needed (plain HTTPS call), but an account, a key and a data-sharing choicePublic content only is sent; a key in the repository secrets
C. Cheap embedding API, Google gemini-embedding-001$0.15 per million tokens, with a free tier; about $0.08 for a full re-embed of the same setNoNone needed, but a key and an account3072 dimensions by default (reducible); larger vectors to store
D. Embeddings on the VPSFreeYes, with 1 CPU and 4 GB shared with the siteA model runtime on the serverRejected by the owner's rule; competes with the site for memory
E. Vectors in the database, compared by the databaseFreeIn the database processpayloadcms-vectorize (MIT, 94 stars, no releases listed)Supports Postgres, Cloudflare and MongoDB only, not SQLite (our database); too small and young
F. Payload AI pluginn/an/an/aNeeds a fork of Payload (from #1484); fails the maintained-library bar
G. Server-side vector functions in libSQLFreeIn the databaseNoneTurso documents vector32 and vector_distance_cos as "Turso Extension" functions; I could not confirm they exist in the libSQL file engine the site's SQLite adapter uses. Unneeded at this size, so not pursued

Why compare in code, not in the database. The site runs Payload on SQLite (@payloadcms/db-sqlite, docs/project.md), a few hundred items, so brute-force cosine is trivial and keeps the database portable if it moves to Postgres later.

Fallback if the owner prefers fewer moving parts: the Action also precomputes each item's top neighbours and stores them in a related-links collection (from, to, score, method; the idea from #1484), so the server does no comparing at all. More stored rows, simpler render.

What needs the owner's sign-off: the choice between A and B or C, and adopting @huggingface/transformers with its model (A), or an API account, key and monthly ceiling (B or C). Recommendation: A, because it costs nothing, needs no key and keeps content inside GitHub. To verify before building: that the library runs in Node in a GitHub Action, that an ONNX build of the chosen model is published, the model weights' size and download time in CI, and the package rules in docs/guidelines/security.md#before-adding-any-new-package (audit, maintenance, size). If A fails any of those, B is the fallback.

Planned steps (split into sub-issues once the owner agrees, each one pull request): the embeddings collection and agent access; the Action; the compare use case with tests and an evaluation list; the "Related" block; backfill of existing content; knowledge notes.

Existing work compared

Searched open and closed issues and the code for related, recommend, semantic, embedding, similar and vector.

  • #1484 (research, scout plus judging model): same goal, superseded by the owner's 2026-11-26 decision (no model, embeddings). Its storage idea (links in their own collection, agents create-only) is the fallback above. Its follow-up drafts were never filed.
  • #1229 (search that understands meaning, under #1227): needs embeddings of a query at request time, so it can't be computed off the server; it can reuse the stored vectors. Cross-linked; no overlap in files.
  • #677 (related content layout): this issue feeds the block it lays out.
  • #576 (tags): not needed here; tags could later add a signal.
  • payloadcms-vectorize (repo, opens in a new tab, read in full): Postgres, Cloudflare and MongoDB only, so it can't be used with SQLite.

Native-first ladder

  1. Native Payload / Next.js: no related-content or vector feature. A json field and an ordinary collection store vectors; jobs, hooks and revalidation already exist. Verified from the repository (SQLite adapter, search plugin) and the join field docs, opens in a new tab.
  2. Official plugins: @payloadcms/plugin-search indexes text for keyword search only; no @payloadcms/* package offers embeddings.
  3. Well-established open source: @huggingface/transformers (Apache-2.0, 16.4k stars) for the embedding step in CI, in option A; no established plugin fits SQLite (option E).
  4. Our code: the cosine ranking, cut-off and upcoming-event filter in a module's domain/ and use-cases/; the collection; the Action script. Small, tested, and needs nothing on the server beyond arithmetic.

Acceptance criteria

  • Not done: The owner has signed off on the model and library (or the API), with a monthly cost ceiling if an API is chosen; the decision is recorded here with the date.
  • Not done: Posts, news, events and the other content types each get a vector, created in CI, never on the server.
  • Not done: A post or event shows related items by meaning below the hand-picked ones, with no editor step; only upcoming events are suggested; nothing shows when nothing is close enough.
  • Not done: The cut-off is tuned on real content with a short recorded evaluation list.
  • Not done: The Action re-embeds only changed items, its key (if any) lives in repository secrets, and agent access is create and update on the embeddings collection only.
  • Not done: No embedding runs on the server, and the page render adds no query per request beyond what the page's cache already allows.
  • Not done: Knowledge notes, docs/reference/ and migrations are updated in the same pull requests.

Files likely touched

A new module's domain/, use-cases/, cms/ (the embeddings collection and access), src/payload.config.ts, src/migrations/, src/payload-types.ts, the news and events related-block mappers and ui/, a CI workflow under .github/workflows/ and its script, package.json (CI-only dependency, if option A), module notes and docs/reference/.

Must not touch

Search (#1229's files), accounts, deploy scripts, intelligence/.

Open questions

needs owner: which embedding option (A recommended), sign-off on @huggingface/transformers and the model weights, and a monthly ceiling if an API is chosen. Blocked by the related-events sub-issue so the hand-picked base exists first.

Area and priority

Areas: cms, frontend, ci, dependencies. Priority: medium. Effort: High (split into steps once the owner agrees).


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab