Skip to main content

internal/infra/pg/entityembedding.go

internal/infra/pg · 734 lines · 29 declarations · source

This file carries the package documentation, rendered on the package page.

Declarations

const EntityEmbeddingInputVersion

const EntityEmbeddingInputVersion = "entity-evidence/v1"

source

const MaxEntityEmbeddingSources

const MaxEntityEmbeddingSources = 4096

source

const MaxEntityEmbeddingPageSources

const MaxEntityEmbeddingPageSources = 4096

source

const MaxEntityEmbeddingTargets

const MaxEntityEmbeddingTargets = 1_000_000

source

type EntityEmbeddingGeneration

type EntityEmbeddingGeneration struct {
ID string `json:"id"`
Project string `json:"project"`
Key string `json:"operation_key"`
Model EmbeddingModel `json:"model"`
TargetCount int64 `json:"target_count"`
After string `json:"after_entity_id,omitempty"`
State string `json:"state"`
Active bool `json:"active"`
Examined int64 `json:"examined"`
Stored int64 `json:"stored"`
CreatedAt time.Time `json:"created_at"`
}

source

type EntityEmbeddingBuildPage

type EntityEmbeddingBuildPage struct {
Examined int `json:"examined"`
Stored int `json:"stored"`
Complete bool `json:"complete"`
After string `json:"after_entity_id,omitempty"`
}

source

type EntityCandidateOptions

type EntityCandidateOptions struct {
Limit int
Candidates int
applicationRead bool
}

source

type EntityCandidate

type EntityCandidate struct {
EntityID string `json:"entity_id"`
IdentityKind string `json:"identity_kind"`
NamePreview string `json:"name_preview"`
NameBytes int `json:"name_bytes"`
NameTruncated bool `json:"name_truncated"`
Similarity float64 `json:"similarity"`
}

source

type EntityCandidateResult

type EntityCandidateResult struct {
Generation EntityEmbeddingGeneration `json:"generation"`
Approximate bool `json:"approximate"`
Candidates []EntityCandidate `json:"candidates"`
}

source

type EntityEmbeddingStore

type EntityEmbeddingStore struct {
pool *pgxpool.Pool
schema Schema
}

source

func NewEntityEmbeddingStore

func NewEntityEmbeddingStore(pool *pgxpool.Pool, schema Schema) *EntityEmbeddingStore

source

func entityEmbeddingModelIdentity

func entityEmbeddingModelIdentity(model EmbeddingModel) string

source

const entityEmbeddingGenerationSQL

const entityEmbeddingGenerationSQL = `SELECT g.generation_id::text,g.scope,g.operation_key::text,
g.model_name,g.model_revision,g.endpoint_hash,g.dimensions,g.target_count,coalesce(b.after_entity_id::text,''),
b.state,coalesce(a.generation_id=g.generation_id,false),b.examined,b.stored,g.created_at
FROM {schema}.entity_embedding_generation g JOIN {schema}.entity_embedding_build b USING(scope,generation_id)
LEFT JOIN {schema}.entity_embedding_active a USING(scope)`

source

func scanEntityEmbeddingGeneration

func scanEntityEmbeddingGeneration(row pgx.Row) (EntityEmbeddingGeneration, error)

source

func entityEmbeddingPartitionName

func entityEmbeddingPartitionName(id string) string

source

method EntityEmbeddingStore.Generation

func (s *EntityEmbeddingStore) Generation(ctx context.Context, scope, id string) (EntityEmbeddingGeneration, error)

source

method EntityEmbeddingStore.Active

func (s *EntityEmbeddingStore) Active(ctx context.Context, scope string) (EntityEmbeddingGeneration, error)

source

method EntityEmbeddingStore.Start

func (s *EntityEmbeddingStore) Start(ctx context.Context, scope, key, actor string, model EmbeddingModel) (EntityEmbeddingGeneration, error)

Start materializes the current named-entity IDs behind the project row lock. Named-entity inserts take that lock in their migration trigger, so an insert is either included or makes this finite snapshot stale after Start commits.

source

type entityEmbeddingInput

type entityEmbeddingInput struct {
entity string
text string
digest []byte
sources []string
sourceDigest []byte
}

source

func digestEntitySources

func digestEntitySources(sources []string) []byte

source

method EntityEmbeddingStore.loadEntityEmbeddingInput

func (s *EntityEmbeddingStore) loadEntityEmbeddingInput(ctx context.Context, q interface {
QueryRow(context.Context, string, ...any) pgx.Row
}, scope, generation, entity string) (entityEmbeddingInput, bool, error)

loadEntityEmbeddingInput bounds transferred aliases, quotes and source IDs before the caller allocates them. Quotes beyond the validation budget cannot affect the 2KB surface.

source

method EntityEmbeddingStore.BuildPage

func (s *EntityEmbeddingStore) BuildPage(ctx context.Context, scope, id, actor string, model EmbeddingModel, limit int, embed EmbeddingBatch) (EntityEmbeddingBuildPage, error)

source

method EntityEmbeddingStore.commitEntityEmbeddingInputs

func (s *EntityEmbeddingStore) commitEntityEmbeddingInputs(ctx context.Context, tx pgx.Tx,
generation EntityEmbeddingGeneration, entries []entityEmbeddingInput, vectors [][]float32) (int, error)

source

method EntityEmbeddingStore.Activate

func (s *EntityEmbeddingStore) Activate(ctx context.Context, scope, id, actor string) error

source

method EntityEmbeddingStore.Repair

func (s *EntityEmbeddingStore) Repair(ctx context.Context, scope, id, actor string) error

source

method EntityEmbeddingStore.Cancel

func (s *EntityEmbeddingStore) Cancel(ctx context.Context, scope, id, actor string) error

source

method EntityEmbeddingStore.Prune

func (s *EntityEmbeddingStore) Prune(ctx context.Context, scope, id, actor string, limit int) (int, error)

source

method EntityEmbeddingStore.Search

func (s *EntityEmbeddingStore) Search(ctx context.Context, scope, actor string, model EmbeddingModel,
vector []float32, options EntityCandidateOptions) (EntityCandidateResult, error)

source

method EntityEmbeddingStore.FindCandidates

func (s *EntityEmbeddingStore) FindCandidates(ctx context.Context, scope string, model EmbeddingModel,
vector []float32, options EntityCandidateOptions) (EntityCandidateResult, error)

FindCandidates is for a caller that has already enforced project authorization and credential audit. It returns candidate identities only and cannot merge or mutate them.

source