pgcache

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: LGPL-3.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pgcache is a tagging.EmbeddingCache backed by PostgreSQL. It needs plain Postgres, with no extension: the embeddings of every index live in one ordinary table. It uses upserts (INSERT ... ON CONFLICT), so PostgreSQL 9.5 or newer.

The cache uses the *sql.DB it is given, so the application imports a Postgres driver and opens the database, for example with github.com/jackc/pgx/v5/stdlib:

db, err := sql.Open("pgx", "postgres://user:password@localhost:5432/app")

Several goroutines, or processes, can write at once with no special setup: a Put is one transaction of upserts made in one fixed order of the keys (model, role, hash), so two Puts of overlapping keys lock their rows in the same order and the second waits for the first instead of deadlocking with it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a tagging.EmbeddingCache on Postgres, in one table of db: Get, Put, Touch, DeleteIndex and Prune are the interface's. It is safe for concurrent use.

func New

func New(ctx context.Context, db *sql.DB) (*Cache, error)

New returns a Cache using db, creating its table if needed, and checks that db is a working Postgres database.

Jump to

Keyboard shortcuts

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