embed

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 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 embed is the remote half of knowledge retrieval: an OpenAI-compatible /v1/embeddings client, and the only place in the tree that sends document text to a third party.

That last sentence is the reason this is its own package with its own boundary. Indexing a folder means every document in it leaves the machine, which is a privacy statement the operator has to be able to make deliberately — so the egress leak scanner runs HERE, before the request, on the same principle as internal/tools/net.go and internal/mcp/conn.go: a secret that reached the corpus is blocked at the boundary rather than embedded and stored forever.

There is no local alternative today. internal/onnx runs a convolutional speaker network in pure Go, and a sentence-transformer needs a transformer's operator set plus a tokenizer; the honest position is a port with a remote adapter behind it, and a local adapter later.

Index

Constants

View Source
const DefaultDims = 768

DefaultDims is what an index is built with unless told otherwise.

Not the model's maximum, on purpose. A provider that offers 3072 offers it for corpora far larger than one person's documents, and the cost is carried in every byte of the index and every comparison: at 3072 a chunk's vector is 12 KB, four times what 768 costs, for a difference in recall that a few thousand chunks cannot show. Providers that support the dimensions parameter train for this (Matryoshka representations), so a shorter vector is a truncation the model expects rather than a lossy afterthought.

View Source
const DefaultModel = "auto"

DefaultModel matches what the chat side does with an unset model: let the endpoint choose. A gateway that fronts several providers is the normal case here, and "auto" is how it is asked.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is an OpenAI-compatible embeddings endpoint.

func New

func New(cfg Config, scanner *secret.Scanner, opts ...Option) *Client

New builds a client. A trailing slash on the base URL is tolerated.

The scanner is a parameter rather than an option because it is not optional in spirit: this is the boundary documents cross on their way off the machine, and it belongs to the workspace whose vault the secrets are in — which is why the client is built per workspace and not once per process.

func (*Client) Dims

func (c *Client) Dims() int

Dims is the vector length this client produces.

func (*Client) Embed

func (c *Client) Embed(ctx context.Context, texts []string) ([][]float32, error)

Embed returns one vector per input, in order.

Inputs are scanned for vault secrets BEFORE the request, and a hit refuses the whole batch rather than dropping the offending chunk: a partial batch would leave the caller believing a document was indexed when part of it silently was not.

func (*Client) Model

func (c *Client) Model() string

Model names the embedding model an index was built with.

type Config

type Config struct {
	BaseURL string
	APIKey  string
	Model   string
	Dims    int
}

Config is where to embed and how. It is resolved by the process that owns configuration — cmd/nocturn, from the environment — rather than read here: a library that reaches for os.Getenv cannot be handed a second endpoint, and cannot be tested without a shell.

The zero Model and Dims mean the defaults above, so a caller that has nothing to say says nothing.

func (Config) Configured

func (c Config) Configured() bool

Configured reports whether there is an endpoint to talk to at all. Unconfigured is a supported state — the knowledge tool then simply does not exist.

type Option

type Option func(*Client)

Option configures a Client. Only the HTTP client is one, for tests; everything else is Config.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient replaces the HTTP client, for tests.

Jump to

Keyboard shortcuts

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