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 ¶
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.
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 ¶
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) Embed ¶
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.
type Config ¶
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 ¶
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.