Repository navigation
Open
Description
Junior has three embedding tables. Each has its own vector column, model tracking, similarity SQL, write loop, and model-change behavior. Raised by @thomasjiangcy in the review of getsentry/junior#3564 and agreed there as a separate refactor.
Current state
| Conversation | Conversation event (#3564, not merged) | Memory | |
|---|---|---|---|
| Schema | packages/junior/src/db/schema/conversation-embeddings.ts |
packages/junior/src/db/schema/conversation-event-embeddings.ts, migration 0116 |
packages/junior-memory/src/db/schema.ts (junior_memory_embeddings), migrations 0002, 0013 |
| Key | conversation_id |
(conversation_id, seq) |
(memory_id, provider, model) |
| Vector | untyped vector |
untyped halfvec, STORAGE MAIN |
untyped vector, its own copy of the column type |
| Index | none, exact cosine in the search query | none, exact scan of one Conversation | partial HNSW on embedding::vector(1024) where dimensions = 1024; 1536 has no ANN index |
| Model tracking | provider, model, dimensions | provider, model, dimensions | provider, model, dimensions, metric, content_hash |
| Staleness | FK to (conversation_id, brief_version); only a newer Brief replaces the row |
events do not change | reads compare content_hash with the current content |
| Write | Brief task after the Brief is stored (chat/briefs/task.ts, chat/conversations/embedding.ts) |
post-Turn event-search task, at most 256 events per run, newest first, behind eventEmbeddings.enabled (chat/conversations/event-embedding.ts) |
on create (store.ts) and the heartbeat backfill, 100 per batch in a 15 s budget (reembed.ts, #2542) |
| Model change | no backfill; search skips the old row until the next Brief | old rows look unembedded; later Turns replace them | new rows go next to old rows; old-model rows stay |
| Delete | FK cascade from the Brief; purge deletes Briefs | FK cascade from the event; purge deletes events | FK cascade from the memory, for example migration 0014 |
| Similarity SQL | conversationSimilarity(), CASE on provider, model, size |
CASE on size in event-search.ts |
embeddingDistance() / embeddingWithinDistance() in junior-memory/src/embedding.ts, literal size cast for the index |
Production uses voyage/voyage-4-lite (1024 dimensions) for all three through embeddingModelId. Memory has about 48k vectors in production.
Problems
- Three copies of the same parts: the vector column type, the size-guarded cosine SQL, the loop that finds rows without a vector, embeds them in batches, checks the model, and upserts, and the embedder interface (
ConversationEmbedder,ConversationEventEmbedder,MemoryEmbeddingProvider). Each copy must remember the guard that keeps vectors of two sizes apart; the review of feat(conversations): Search a Conversation's event history by words and meaning #3564 found one copy without it. - A model change behaves three ways. Conversation search loses its meaning ranking for each Conversation until that Conversation gets a new Brief.
- Precision, storage, and index choices are made per table:
halfveconly for events, HNSW only for memories. - No single place shows how much of each kind has a vector of the configured model.
Goal
One way to store, find, refresh, and delete embeddings, with one model-change path. Purges must still delete derived vectors, memory recall must not change, and plugins must still reach shared code only through @sentry/junior-plugin-api.
Open questions
- One core table keyed by owner kind and id, or shared code over the current tables? A table keyed by owner kind cannot keep the FK cascades that purges and memory deletes depend on.
- How memory reaches shared storage: a plugin-api contract now, or after Move Memory fully into Junior core #1861 moves Memory into core.
halfvecfor all kinds, orvector? Memory recall uses distance cutoffs.- Keep rows of old models (memory today) or replace in place (events today)?
- Existing rows: copy them, or re-embed them through the backfill?
Requested by @BYK.
via @BYK.
--
Metadata
Metadata
Assignees
Labels
No labels
Activity
ref(embeddings): Share embedding helpers across Conversations, events…