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"
const MaxReportEmbeddingSources
const MaxReportEmbeddingSources = 4096
const MaxReportEmbeddingPageSources
const MaxReportEmbeddingPageSources = 4096
const MaxReportEmbeddingTargets
const MaxReportEmbeddingTargets = 1_000_000
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"`
}
type ReportEmbeddingBuildPage
type ReportEmbeddingBuildPage struct {
Examined int `json:"examined"`
Stored int `json:"stored"`
Complete bool `json:"complete"`
After string `json:"after_report_id,omitempty"`
}
type ReportCandidateOptions
type ReportCandidateOptions struct {
Limit int
Candidates int
applicationRead bool
}
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"`
}
type ReportCandidateResult
type ReportCandidateResult struct {
Generation ReportEmbeddingGeneration `json:"generation"`
Approximate bool `json:"approximate"`
Candidates []ReportCandidate `json:"candidates"`
}
type ReportEmbeddingStore
type ReportEmbeddingStore struct {
pool *pgxpool.Pool
schema Schema
}
func NewReportEmbeddingStore
func NewReportEmbeddingStore(pool *pgxpool.Pool, schema Schema) *ReportEmbeddingStore
func reportEmbeddingModelIdentity
func reportEmbeddingModelIdentity(model EmbeddingModel) string
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)`
func scanReportEmbeddingGeneration
func scanReportEmbeddingGeneration(row pgx.Row) (ReportEmbeddingGeneration, error)
func reportEmbeddingPartitionName
func reportEmbeddingPartitionName(id string) string
method ReportEmbeddingStore.Generation
func (s *ReportEmbeddingStore) Generation(ctx context.Context, scope, id string) (ReportEmbeddingGeneration, error)
method ReportEmbeddingStore.Active
func (s *ReportEmbeddingStore) Active(ctx context.Context, scope string) (ReportEmbeddingGeneration, error)
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.
type reportEmbeddingInput
type reportEmbeddingInput struct {
report string
text string
digest []byte
sources []string
sourceDigest []byte
}
func digestReportSources
func digestReportSources(sources []string) []byte
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.
method ReportEmbeddingStore.BuildPage
func (s *ReportEmbeddingStore) BuildPage(ctx context.Context, scope, id, actor string, model EmbeddingModel, limit int, embed EmbeddingBatch) (ReportEmbeddingBuildPage, error)
method ReportEmbeddingStore.commitReportEmbeddingInputs
func (s *ReportEmbeddingStore) commitReportEmbeddingInputs(ctx context.Context, tx pgx.Tx,
generation ReportEmbeddingGeneration, entries []reportEmbeddingInput, vectors [][]float32) (int, error)
method ReportEmbeddingStore.Activate
func (s *ReportEmbeddingStore) Activate(ctx context.Context, scope, id, actor string) error
method ReportEmbeddingStore.Repair
func (s *ReportEmbeddingStore) Repair(ctx context.Context, scope, id, actor string) error
method ReportEmbeddingStore.Cancel
func (s *ReportEmbeddingStore) Cancel(ctx context.Context, scope, id, actor string) error
method ReportEmbeddingStore.Prune
func (s *ReportEmbeddingStore) Prune(ctx context.Context, scope, id, actor string, limit int) (int, error)
method ReportEmbeddingStore.Search
func (s *ReportEmbeddingStore) Search(ctx context.Context, scope, actor string, model EmbeddingModel,
vector []float32, options ReportCandidateOptions) (ReportCandidateResult, error)
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.