Documentation
¶
Index ¶
- func CosineSimilarity(a, b Vector) float64
- func Normalize(v Vector)
- type Embedder
- type OllamaEmbedder
- type SearchHit
- type Store
- func (s *Store) Add(id string, vec Vector)
- func (s *Store) Count() int
- func (s *Store) ModelID() string
- func (s *Store) Remove(id string)
- func (s *Store) Search(query Vector, k int) []SearchHit
- func (s *Store) SearchFiltered(query Vector, k int, allow func(id string) bool) []SearchHit
- func (s *Store) SetModelID(model string)
- type Vector
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) SearchFiltered ¶ added in v0.4.0
SearchFiltered returns the highest-similarity hits accepted by allow. It applies the predicate before k so hidden vectors never exhaust a page.
func (*Store) SetModelID ¶
SetModelID sets the model identifier. If it changes, the caller is responsible for clearing and rebuilding the store.