collectionindex

package
v1.118.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package collectionindex is the curated-collection consumer of the shared indexjobs framework (#550). It registers a Source/Sink pair under source_kind = "portal-collections" so the reconciler embeds collections off the request path: a newly created collection (whose vector is still NULL), one whose sections changed, or one left stale by a provider model swap self-heals on the next sweep.

Like the prompt, memory, and asset consumers, collections store their vectors inline on the portal_collections table (one embedding per row). So this package's Store reads and writes the embedding / embedding_model / embedding_text_hash columns directly: a collection IS its own indexing unit. SourceID is the collection id; each unit yields exactly one Item whose text is portal.CollectionIndexText (name + description + the denormalized sections_text, i.e. section titles + descriptions).

Only non-deleted collections are indexed. Gap detection and coverage both filter on deleted_at IS NULL.

Index

Constants

View Source
const SourceKind = "portal-collections"

SourceKind is the indexjobs source_kind this package serves.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink implements indexjobs.Sink for the portal-collections kind over the embedding columns of the portal_collections table. currentModel is the provider model the gap query diffs stored rows against, so a model swap re-embeds rows stamped with the previous model.

func NewSink

func NewSink(store *Store, currentModel string) *Sink

NewSink returns a Sink backed by the given store. currentModel is the embedding provider's model identifier (embedding.ModelName); pass "" on a deployment whose provider does not name its model, in which case every row matches "" and only NULL-embedding rows are treated as gaps.

func (*Sink) Coverage

func (s *Sink) Coverage(ctx context.Context) (indexjobs.Coverage, error)

Coverage reports the portal-collections kind's indexed-vs-expected totals. ExpectedKnown is true: every non-deleted collection is expected to converge to one vector.

func (*Sink) FindGaps

func (s *Sink) FindGaps(ctx context.Context) ([]string, error)

FindGaps returns non-deleted collection ids whose embedding is missing or was produced by a model other than the current one.

func (*Sink) Kind

func (*Sink) Kind() string

Kind reports the portal-collections source kind.

func (*Sink) ListExisting

func (s *Sink) ListExisting(ctx context.Context, key indexjobs.Key) (map[string]indexjobs.Vector, error)

ListExisting returns the collection's persisted vector keyed by item id for the worker's dedup pass.

func (*Sink) StampExpected

func (*Sink) StampExpected(context.Context, indexjobs.Key, int) error

StampExpected is a no-op for collections. Gap detection is condition-based, not count-based, so there is no expected count to record per unit.

func (*Sink) Upsert

func (s *Sink) Upsert(ctx context.Context, key indexjobs.Key, rows []indexjobs.Vector) error

Upsert writes the collection's vector. The collection unit holds one item and has no sibling rows, so it delegates to the shared store write.

func (*Sink) UpsertBatch

func (s *Sink) UpsertBatch(ctx context.Context, key indexjobs.Key, rows []indexjobs.Vector) error

UpsertBatch is identical to Upsert for collections (single-item unit, no rows outside the batch to preserve).

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source implements indexjobs.Source for the portal-collections kind. A unit is one collection (SourceID = collection id) and yields exactly one item: the collection's composed embed text. The worker embeds it and the Sink writes the vector back onto the same row.

func NewSource

func NewSource(store *Store) *Source

NewSource returns a Source backed by the given store.

func (*Source) Kind

func (*Source) Kind() string

Kind reports the portal-collections source kind.

func (*Source) LoadItems

func (s *Source) LoadItems(ctx context.Context, sourceID string) ([]indexjobs.Item, error)

LoadItems returns the collection's single embeddable item. A collection soft-deleted between enqueue and claim yields an empty slice (a clean completion that writes no vector), per the Source contract.

func (*Source) OnSucceeded

func (*Source) OnSucceeded(string)

OnSucceeded is a no-op: the ranked search reads embeddings from the portal_collections table directly on every query, so there is no in-memory cache to refresh after a backfill writes a vector.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store reads and writes collection embedding state on the portal_collections table for the indexjobs collections consumer. It touches only the embedding columns (embedding, embedding_model, embedding_text_hash) and the denormalized sections_text it reads, so it does not widen the request-path store contract. The request-path Update/SetSections clears the embedding when a collection's indexed text changes; this Store writes it back.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore returns a Store over the given database.

func (*Store) Coverage

func (s *Store) Coverage(ctx context.Context) (indexed, expected int, err error)

Coverage returns the number of non-deleted collections with an embedding (indexed) and the total number of non-deleted collections (expected).

func (*Store) FindGaps

func (s *Store) FindGaps(ctx context.Context, currentModel string) ([]string, error)

FindGaps returns the ids of non-deleted collections whose embedding is missing or was produced by a model other than the current provider's.

func (*Store) GetIndexText

func (s *Store) GetIndexText(ctx context.Context, id string) (string, error)

GetIndexText returns the composed embed text for a non-deleted collection. A collection soft-deleted between enqueue and claim yields errNotIndexable so the Source returns an empty item set. The composition is portal.CollectionIndexText, the same one the request-path search ranks against (name + description + sections_text).

func (*Store) ListVectors

func (s *Store) ListVectors(ctx context.Context, id string) (map[string]indexjobs.Vector, error)

ListVectors returns the collection's persisted embedding keyed by item id (the collection id), for the worker's text-hash + model dedup pass. A collection with no embedding yields an empty map, so the worker embeds it.

func (*Store) UpsertVectors

func (s *Store) UpsertVectors(ctx context.Context, id string, rows []indexjobs.Vector) error

UpsertVectors writes the embedding back onto the collection. updated_at is deliberately left untouched: a background embed is not a user-visible edit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL