Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CosineSimilarity ¶
CosineSimilarity computes cosine similarity between two vectors. Returns 0 if vectors have different lengths or either is zero.
Types ¶
type Embedder ¶
type Embedder interface {
Embed(text string) (Vector, error)
Model() string // returns the model identifier
}
Embedder generates embedding vectors from text.
type OllamaEmbedder ¶
type OllamaEmbedder struct {
// contains filtered or unexported fields
}
OllamaEmbedder calls the Ollama HTTP API for embeddings.
func NewOllama ¶
func NewOllama(baseURL, model string) *OllamaEmbedder
NewOllama creates an Ollama embedder. baseURL is the Ollama API URL (e.g. "http://localhost:11434"). model is the embedding model name (e.g. "nomic-embed-text").
func (*OllamaEmbedder) Embed ¶
func (o *OllamaEmbedder) Embed(text string) (Vector, error)
Embed sends a request to POST /api/embed and returns the vector.
func (*OllamaEmbedder) Model ¶
func (o *OllamaEmbedder) Model() string
Model returns the model identifier.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an in-memory vector store with brute-force cosine search. Vectors are normalized on Add, so cosine similarity reduces to dot product.
func (*Store) Add ¶
Add adds or updates a document's vector. The vector is normalized before storage.
func (*Store) ModelID ¶
ModelID returns the model identifier used for stored vectors, or "" if not set.
func (*Store) Search ¶
Search returns the top-k most similar documents to the query vector. Returns results sorted by descending similarity. Because stored vectors are normalized, cosine similarity == dot product.
func (*Store) SetModelID ¶
SetModelID sets the model identifier. If it changes, the caller is responsible for clearing and rebuilding the store.