Documentation
¶
Overview ¶
Package meta provides extensions to the HNSW library for storing and retrieving JSON metadata alongside vectors.
Index ¶
- type MemoryMetadataStore
- func (s *MemoryMetadataStore[K]) Add(key K, metadata json.RawMessage) error
- func (s *MemoryMetadataStore[K]) BatchAdd(keys []K, metadatas []json.RawMessage) error
- func (s *MemoryMetadataStore[K]) BatchDelete(keys []K) []bool
- func (s *MemoryMetadataStore[K]) BatchGet(keys []K) []json.RawMessage
- func (s *MemoryMetadataStore[K]) Delete(key K) bool
- func (s *MemoryMetadataStore[K]) ForEach(fn func(key K, metadata json.RawMessage))
- func (s *MemoryMetadataStore[K]) Get(key K) (json.RawMessage, bool)
- type MetadataError
- type MetadataGraph
- func (g *MetadataGraph[K]) Add(node MetadataNode[K]) error
- func (g *MetadataGraph[K]) BatchAdd(nodes []MetadataNode[K]) error
- func (g *MetadataGraph[K]) BatchDelete(keys []K) []bool
- func (g *MetadataGraph[K]) BatchSearch(queries []hnsw.Vector, k int) ([][]MetadataSearchResult[K], error)
- func (g *MetadataGraph[K]) BatchSearchWithNegatives(queries []hnsw.Vector, negatives []hnsw.Vector, k int, negWeight float32) ([][]MetadataSearchResult[K], error)
- func (g *MetadataGraph[K]) Delete(key K) bool
- func (g *MetadataGraph[K]) Get(key K) (MetadataNode[K], bool)
- func (g *MetadataGraph[K]) Search(query hnsw.Vector, k int) ([]MetadataSearchResult[K], error)
- func (g *MetadataGraph[K]) SearchWithNegative(query, negative hnsw.Vector, k int, negWeight float32) ([]MetadataSearchResult[K], error)
- type MetadataNode
- type MetadataSearchResult
- type MetadataStore
- type SearchResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemoryMetadataStore ¶
MemoryMetadataStore is an in-memory implementation of MetadataStore.
func NewMemoryMetadataStore ¶
func NewMemoryMetadataStore[K cmp.Ordered]() *MemoryMetadataStore[K]
NewMemoryMetadataStore creates a new in-memory metadata store.
func (*MemoryMetadataStore[K]) Add ¶
func (s *MemoryMetadataStore[K]) Add(key K, metadata json.RawMessage) error
Add adds metadata for a key.
func (*MemoryMetadataStore[K]) BatchAdd ¶
func (s *MemoryMetadataStore[K]) BatchAdd(keys []K, metadatas []json.RawMessage) error
BatchAdd adds metadata for multiple keys.
func (*MemoryMetadataStore[K]) BatchDelete ¶
func (s *MemoryMetadataStore[K]) BatchDelete(keys []K) []bool
BatchDelete removes metadata for multiple keys.
func (*MemoryMetadataStore[K]) BatchGet ¶
func (s *MemoryMetadataStore[K]) BatchGet(keys []K) []json.RawMessage
BatchGet retrieves metadata for multiple keys.
func (*MemoryMetadataStore[K]) Delete ¶
func (s *MemoryMetadataStore[K]) Delete(key K) bool
Delete removes metadata for a key.
func (*MemoryMetadataStore[K]) ForEach ¶ added in v0.3.0
func (s *MemoryMetadataStore[K]) ForEach(fn func(key K, metadata json.RawMessage))
ForEach iterates over all metadata entries and calls the provided function for each entry.
func (*MemoryMetadataStore[K]) Get ¶
func (s *MemoryMetadataStore[K]) Get(key K) (json.RawMessage, bool)
Get retrieves metadata for a key.
type MetadataError ¶
type MetadataError struct {
Message string
}
MetadataError represents an error related to metadata operations.
type MetadataGraph ¶
type MetadataGraph[K cmp.Ordered] struct { Graph *hnsw.Graph[K] Store MetadataStore[K] }
MetadataGraph combines an HNSW graph with metadata storage.
func NewMetadataGraph ¶
func NewMetadataGraph[K cmp.Ordered](graph *hnsw.Graph[K], store MetadataStore[K]) *MetadataGraph[K]
NewMetadataGraph creates a new MetadataGraph with the given HNSW graph and metadata store.
func (*MetadataGraph[K]) Add ¶
func (g *MetadataGraph[K]) Add(node MetadataNode[K]) error
Add adds a node with metadata to both the graph and the metadata store.
func (*MetadataGraph[K]) BatchAdd ¶
func (g *MetadataGraph[K]) BatchAdd(nodes []MetadataNode[K]) error
BatchAdd adds multiple nodes with metadata in a single operation.
func (*MetadataGraph[K]) BatchDelete ¶
func (g *MetadataGraph[K]) BatchDelete(keys []K) []bool
BatchDelete removes multiple nodes in a single operation.
func (*MetadataGraph[K]) BatchSearch ¶
func (g *MetadataGraph[K]) BatchSearch(queries []hnsw.Vector, k int) ([][]MetadataSearchResult[K], error)
BatchSearch performs multiple searches in a single operation and attaches metadata to results.
func (*MetadataGraph[K]) BatchSearchWithNegatives ¶
func (g *MetadataGraph[K]) BatchSearchWithNegatives(queries []hnsw.Vector, negatives []hnsw.Vector, k int, negWeight float32) ([][]MetadataSearchResult[K], error)
BatchSearchWithNegatives performs multiple searches with negative examples in a single operation and attaches metadata to results.
func (*MetadataGraph[K]) Delete ¶
func (g *MetadataGraph[K]) Delete(key K) bool
Delete removes a node from both the graph and the metadata store.
func (*MetadataGraph[K]) Get ¶
func (g *MetadataGraph[K]) Get(key K) (MetadataNode[K], bool)
Get retrieves a node with its metadata.
func (*MetadataGraph[K]) Search ¶
func (g *MetadataGraph[K]) Search(query hnsw.Vector, k int) ([]MetadataSearchResult[K], error)
Search performs a search and attaches metadata to results.
func (*MetadataGraph[K]) SearchWithNegative ¶
func (g *MetadataGraph[K]) SearchWithNegative(query, negative hnsw.Vector, k int, negWeight float32) ([]MetadataSearchResult[K], error)
SearchWithNegative performs a search with a negative example and attaches metadata to results.
type MetadataNode ¶
MetadataNode extends the basic HNSW Node with JSON metadata.
func NewMetadataNode ¶
func NewMetadataNode[K cmp.Ordered](node hnsw.Node[K], metadata interface{}) (MetadataNode[K], error)
NewMetadataNode creates a new MetadataNode with the given node and metadata.
func (MetadataNode[K]) GetMetadataAs ¶
func (n MetadataNode[K]) GetMetadataAs(target interface{}) error
GetMetadataAs unmarshals the metadata into the provided target.
type MetadataSearchResult ¶
type MetadataSearchResult[K cmp.Ordered] struct { SearchResult[K] Metadata json.RawMessage }
MetadataSearchResult extends the basic HNSW SearchResult with metadata.
func (MetadataSearchResult[K]) GetMetadataAs ¶
func (r MetadataSearchResult[K]) GetMetadataAs(target interface{}) error
GetMetadataAs unmarshals the metadata into the provided target.
type MetadataStore ¶
type MetadataStore[K cmp.Ordered] interface { // Add adds metadata for a key. Add(key K, metadata json.RawMessage) error // Get retrieves metadata for a key. Get(key K) (json.RawMessage, bool) // Delete removes metadata for a key. Delete(key K) bool // BatchAdd adds metadata for multiple keys. BatchAdd(keys []K, metadatas []json.RawMessage) error // BatchGet retrieves metadata for multiple keys. BatchGet(keys []K) []json.RawMessage // BatchDelete removes metadata for multiple keys. BatchDelete(keys []K) []bool // ForEach iterates over all metadata entries and calls the provided function for each entry. ForEach(fn func(key K, metadata json.RawMessage)) }
MetadataStore is an interface for storing and retrieving metadata.
type SearchResult ¶
SearchResult represents a search result from the HNSW graph. This is a copy of the type from the HNSW package to avoid import cycles.