Skip to main content

internal/infra/pg/reportembedding.go

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

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

Declarations​

const ReportEmbeddingInputVersion​

const ReportEmbeddingInputVersion = "community-report/v1"

source

const MaxReportEmbeddingSources​

const MaxReportEmbeddingSources = 4096

source

const MaxReportEmbeddingPageSources​

const MaxReportEmbeddingPageSources = 4096

source

const MaxReportEmbeddingTargets​

const MaxReportEmbeddingTargets = 1_000_000

source

type ReportEmbeddingGeneration​

type ReportEmbeddingGeneration 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_report_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 ReportEmbeddingBuildPage​

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

source

type ReportCandidateOptions​

type ReportCandidateOptions struct {
Limit int
Candidates int
applicationRead bool
}

source

type ReportCandidate​

type ReportCandidate struct {
ReportID string `json:"report_id"`
CommunityID string `json:"community_id"`
TitlePreview string `json:"title_preview"`
TitleBytes int `json:"title_bytes"`
TitleTruncated bool `json:"title_truncated"`
SummaryPreview string `json:"summary_preview"`
SummaryBytes int `json:"summary_bytes"`
SummaryTruncated bool `json:"summary_truncated"`
Importance float32 `json:"importance"`
Similarity float64 `json:"similarity"`
}

source

type ReportCandidateResult​

type ReportCandidateResult struct {
Generation ReportEmbeddingGeneration `json:"generation"`
Approximate bool `json:"approximate"`
Candidates []ReportCandidate `json:"candidates"`
}

source

type ReportEmbeddingStore​

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

source

func NewReportEmbeddingStore​

func NewReportEmbeddingStore(pool *pgxpool.Pool, schema Schema) *ReportEmbeddingStore

source

func reportEmbeddingModelIdentity​

func reportEmbeddingModelIdentity(model EmbeddingModel) string

source

const reportEmbeddingGenerationSQL​

const reportEmbeddingGenerationSQL = `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_report_id::text,''),
b.state,coalesce(a.generation_id=g.generation_id,false),b.examined,b.stored,g.created_at
FROM {schema}.report_embedding_generation g JOIN {schema}.report_embedding_build b USING(scope,generation_id)
LEFT JOIN {schema}.report_embedding_active a USING(scope)`

source

func scanReportEmbeddingGeneration​

func scanReportEmbeddingGeneration(row pgx.Row) (ReportEmbeddingGeneration, error)

source

func reportEmbeddingPartitionName​

func reportEmbeddingPartitionName(id string) string

source

method ReportEmbeddingStore.Generation​

func (s *ReportEmbeddingStore) Generation(ctx context.Context, scope, id string) (ReportEmbeddingGeneration, error)

source

method ReportEmbeddingStore.Active​

func (s *ReportEmbeddingStore) Active(ctx context.Context, scope string) (ReportEmbeddingGeneration, error)

source

method ReportEmbeddingStore.Start​

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

Start materializes current report IDs behind the project row lock. Report writes take that lock in their migration trigger, so a concurrent report is included or makes the finite snapshot stale.

source

type reportEmbeddingInput​

type reportEmbeddingInput struct {
report string
text string
digest []byte
sources []string
sourceDigest []byte
}

source

func digestReportSources​

func digestReportSources(sources []string) []byte

source

method ReportEmbeddingStore.loadReportEmbeddingInput​

func (s *ReportEmbeddingStore) loadReportEmbeddingInput(ctx context.Context, q interface {
QueryRow(context.Context, string, ...any) pgx.Row
}, scope, generation, reportID string) (reportEmbeddingInput, bool, error)

loadReportEmbeddingInput reads the report and its exact source registrations. The pure report package bounds and validates the semantic input before provider egress.

source

method ReportEmbeddingStore.BuildPage​

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

source

method ReportEmbeddingStore.commitReportEmbeddingInputs​

func (s *ReportEmbeddingStore) commitReportEmbeddingInputs(ctx context.Context, tx pgx.Tx,
generation ReportEmbeddingGeneration, entries []reportEmbeddingInput, vectors [][]float32) (int, error)

source

method ReportEmbeddingStore.Activate​

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

source

method ReportEmbeddingStore.Repair​

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

source

method ReportEmbeddingStore.Cancel​

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

source

method ReportEmbeddingStore.Prune​

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

source

method ReportEmbeddingStore.Search​

func (s *ReportEmbeddingStore) Search(ctx context.Context, scope, actor string, model EmbeddingModel,
vector []float32, options ReportCandidateOptions) (ReportCandidateResult, error)

source

method ReportEmbeddingStore.FindCandidates​

func (s *ReportEmbeddingStore) FindCandidates(ctx context.Context, scope string, model EmbeddingModel,
vector []float32, options ReportCandidateOptions) (ReportCandidateResult, error)

FindCandidates is for a caller that has already enforced project authorization and credential audit. It returns bounded report previews and cannot mutate memory.

source