Documentation
¶
Overview ¶
Package inmemory implements exact vector search over process-local records. Upsert and Query accept precomputed coordinates in the configured space. Query evaluates metadata before scoring, scans all records under a read lock, and orders score ties by document ID. The Store owns no model or I/O.
Example ¶
store, err := inmemory.NewStore(context.Background(), inmemory.StoreConfig{Space: testSpace, Dimensions: 4})
if err != nil {
panic(err)
}
fmt.Println(store.Len())
Output: 0
Index ¶
- Constants
- func CosineSimilarity(left, right []float64) vectorstore.Score
- func DotProductSimilarity(left, right []float64) vectorstore.Score
- func EuclideanSimilarity(left, right []float64) vectorstore.Score
- type Similarity
- type Store
- func (s *Store) CheckDocuments(ctx context.Context, space vectorstore.SpaceID, docs []*document.Document) error
- func (s *Store) CheckQuery(ctx context.Context, space vectorstore.SpaceID, opts vectorstore.SearchOptions) error
- func (s *Store) Clear()
- func (s *Store) DeleteIDs(ctx context.Context, ids []string) error
- func (s *Store) DeleteWhere(ctx context.Context, expr filter.Predicate) error
- func (s *Store) Len() int
- func (s *Store) Query(ctx context.Context, req *vectorstore.Query) (*vectorstore.SearchResponse, error)
- func (s *Store) Upsert(ctx context.Context, batch *vectorstore.Batch) error
- type StoreConfig
Examples ¶
Constants ¶
const Provider = "InMemory"
Variables ¶
This section is empty.
Functions ¶
func CosineSimilarity ¶
func CosineSimilarity(left, right []float64) vectorstore.Score
CosineSimilarity is the default for StoreConfig.Similarity — cos(θ) mapped into [0, 1] via (1 + cos) / 2. Returns 0.5 (the "no information" midpoint) when either vector has zero magnitude rather than NaN.
func DotProductSimilarity ¶
func DotProductSimilarity(left, right []float64) vectorstore.Score
DotProductSimilarity maps the unbounded inner product monotonically into the common score range when vector magnitude is meaningful. Products and their sum retain their exact values until the final score conversion.
func EuclideanSimilarity ¶
func EuclideanSimilarity(left, right []float64) vectorstore.Score
EuclideanSimilarity maps distance d to 1/(1+d), preserving magnitude differences.
Types ¶
type Similarity ¶
type Similarity func(left, right []float64) vectorstore.Score
Similarity scores two equal-length vectors; higher means more similar. Implementations must be deterministic and symmetric: Similarity(a, b) == Similarity(b, a). Returning vectorstore.Score keeps custom strategies inside the same normalized contract as every provider.
Both slices are borrowed read-only for the duration of the call: an implementation must not modify or retain them. The store scores a record against the shared indexed vector, so an in-place write would corrupt the index and race concurrent searches. Honoring this, Similarity may be called concurrently, which is how Store.Query scans the index.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a concurrency-safe, in-process vector store. Upsert snapshots documents and coordinates and Query returns detached results in deterministic score order. Query scans the full index; all records are lost when the process exits.
func (*Store) CheckDocuments ¶ added in v0.59.0
func (s *Store) CheckDocuments(ctx context.Context, space vectorstore.SpaceID, docs []*document.Document) error
CheckDocuments rejects an invalid space or document set before an index writer spends an embedding call. The memory store supports complete media.
func (*Store) CheckQuery ¶ added in v0.59.0
func (s *Store) CheckQuery(ctx context.Context, space vectorstore.SpaceID, opts vectorstore.SearchOptions) error
func (*Store) Clear ¶
func (s *Store) Clear()
Clear removes all records while retaining the bound coordinate space.
func (*Store) DeleteWhere ¶
func (*Store) Query ¶ added in v0.59.0
func (s *Store) Query(ctx context.Context, req *vectorstore.Query) (*vectorstore.SearchResponse, error)
type StoreConfig ¶
type StoreConfig struct {
Space vectorstore.SpaceID
Dimensions int
Similarity Similarity
}
StoreConfig binds one immutable coordinate space and dimension. A nil Similarity selects CosineSimilarity.
func (StoreConfig) Validate ¶
func (s StoreConfig) Validate() error