learnings

package
v1.37.0 Latest Latest
Warning

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

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

Documentation

Overview

Package learnings persists review findings so future reviews on the same repo/symbol can reference prior outcomes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

type Embedder interface {
	Embed(ctx context.Context, text string) ([]float32, error)
}

Embedder abstracts the embedding client; pass nil to disable vector updates and fall back to exact (repo, symbol) lookups.

type Record

type Record struct {
	Repo          string `json:"repo"`
	Symbol        string `json:"symbol"`
	RiskLevel     string `json:"risk_level,omitempty"`
	ReviewOutcome string `json:"review_outcome,omitempty"`
	Flag          string `json:"flag,omitempty"`
	Note          string `json:"note,omitempty"`
	PRURL         string `json:"pr_url,omitempty"`
}

Record is a single learning.

RiskLevel and ReviewOutcome are orthogonal:

  • RiskLevel is written by the impact-analysis path (review_pr) and uses the vocabulary low|medium|high.
  • ReviewOutcome is written by the posted-review path (review_pr with dry_run=false) and uses the vocabulary good|neutral|bad (mapped from the GitHub review event).

Either (or both) may be empty on a given row depending on which writer produced it.

type Store

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

Store persists learnings in Postgres (pgvector).

func New

func New(ctx context.Context, dsn string, emb Embedder) (*Store, error)

New opens a pool. Caller must call Close.

After migrating the schema it attempts (at most once per DSN per process) to transfer table ownership to CURRENT_USER (best-effort: warns instead of failing if the connected role is not the current table owner — e.g. after a superuser pg_restore left review_learnings owned by the restoring role).

func (*Store) Close

func (s *Store) Close()

Close releases the pool.

func (*Store) HasEmbedder added in v1.20.0

func (s *Store) HasEmbedder() bool

HasEmbedder reports whether this store has a configured Embedder for vector similarity search. When false, NearestVector calls will error.

func (*Store) Nearest

func (s *Store) Nearest(ctx context.Context, repo, symbol string, k int) ([]Record, error)

Nearest returns up to k prior learnings for the same (repo, symbol). (Vector search is added later; exact match is enough for v1.)

func (*Store) NearestByRepo added in v1.20.0

func (s *Store) NearestByRepo(ctx context.Context, repo string, k int) ([]Record, error)

NearestByRepo returns up to k prior learnings for the given repo, ordered by creation time descending. It matches any symbol.

func (*Store) NearestVector

func (s *Store) NearestVector(ctx context.Context, query string, k int) ([]Record, error)

NearestVector returns up to k prior learnings closest to the given query string by cosine distance over the embedding column. It requires a configured Embedder; callers should fall back to the exact (repo, symbol) Nearest path when no embedder is available.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, r Record) error

Upsert inserts a learning. If an embedder is configured, the flag+note is embedded for future similarity search.

Jump to

Keyboard shortcuts

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