Documentation
¶
Overview ¶
Package index defines a top-level index interface for executing search queries against a collection of documents. Contains helpers for searching multiple indexes at once.
Index ¶
- func NewTurbopufferClient(apiKey string) *turbopuffer.Client
- type AttributesSelector
- type DeleteSelector
- type DistanceMetric
- type Document
- type DocumentAttribute
- type DocumentID
- type Filter
- type FilterCondition
- type FilterOp
- type InMemory
- type Index
- type MultiIndex
- type Query
- type ScoredDocument
- type TurbopufferIndex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTurbopufferClient ¶
func NewTurbopufferClient(apiKey string) *turbopuffer.Client
NewTurbopufferClient creates a new Turbopuffer client from an API key.
Types ¶
type AttributesSelector ¶
type AttributesSelector []string
AttributesSelector is a list of attributes to include in search results. If nil, all attributes are included. If empty, no attributes are included.
type DeleteSelector ¶
type DeleteSelector struct {
IDs []DocumentID
Filter *Filter
}
DeleteSelector is a selector for deleting documents from an index.
type DistanceMetric ¶
type DistanceMetric int
DistanceMetric is an enumeration over the various supported distance metrics.
const (
CosineDistance DistanceMetric = iota
)
Supported distance metrics.
func (DistanceMetric) ComputeDistance ¶
func (dm DistanceMetric) ComputeDistance(a, b []float32) float32
type Document ¶
type Document struct {
ID DocumentID
Vector []float32
Attributes map[string]DocumentAttribute
}
Document is a single document within an index.
func (*Document) GetAttributes ¶
func (d *Document) GetAttributes(selector AttributesSelector) map[string]DocumentAttribute
GetAttributes returns a map of attributes contained within a document, chosen by a selector.
func (*Document) MatchesFilter ¶
MatchesFilter checks if a document matches a provided filter. Note that this implementation may not match the behaviour of other implementations, i.e. those provided by indexing providers.
func (*Document) MatchesFilterCondition ¶
func (d *Document) MatchesFilterCondition(fc *FilterCondition) bool
MatchesFilterCondition checks if a document matches a provided filter condition.
type DocumentAttribute ¶
DocumentAttribute is an attached attribute to a document.
func NewDocumentAttributeString ¶
func NewDocumentAttributeString(s string) DocumentAttribute
NewDocumentAttributeString creates a new string document attribute.
type Filter ¶
type Filter struct {
Condition *FilterCondition
And []Filter
Or []Filter
}
Filter is a filter for searching documents in an index.
type FilterCondition ¶
type FilterCondition struct {
Key string
Op FilterOp
Input DocumentAttribute
}
FilterCondition is a single condition within a filter.
type InMemory ¶
type InMemory struct {
// contains filtered or unexported fields
}
func NewInMemory ¶
func NewInMemory(dims int, distMetric DistanceMetric) *InMemory
NewInMemory creates a new in-memory index. All documents are stored in memory and are exhaustively searched for each query. Mostly used for testing etc.
func (*InMemory) Delete ¶
func (im *InMemory) Delete(_ context.Context, selector DeleteSelector) error
type Index ¶
type Index interface {
// Upsert adds or updates the given documents in the index, replacing any existing documents
// with the same ID. Upsert is atomic: if an error is returned, the index is unchanged.
Upsert(ctx context.Context, docs []Document) error
// Deletes documents according to a selector from the index.
Delete(ctx context.Context, selector DeleteSelector) error
// Query searches the index for documents matching the given query.
Query(ctx context.Context, query Query) ([]ScoredDocument, error)
}
An Index contains a collection of documents and provides a way to search them.
type MultiIndex ¶
type MultiIndex struct {
// contains filtered or unexported fields
}
MultiIndex is an index that combines multiple indexes into a single index. Upserts are sent to all indexes, as are deletes. Queries are sent to all indexes, and the results are combined and re-sorted.
func NewMultiIndex ¶
func NewMultiIndex(indexes ...Index) *MultiIndex
NewMultiIndex creates a new multi-index that combines the given indexes into a single index.
func (*MultiIndex) Delete ¶
func (mi *MultiIndex) Delete(ctx context.Context, selector DeleteSelector) error
func (*MultiIndex) Query ¶
func (mi *MultiIndex) Query(ctx context.Context, query Query) ([]ScoredDocument, error)
type Query ¶
type Query struct {
MaxResults int
Vector []float32
Text *string
Filter *Filter
IncludeVector bool
IncludeAttributes AttributesSelector
}
Query is a search query for an index.
type ScoredDocument ¶
ScoredDocument returns a document with an associated score.
type TurbopufferIndex ¶
type TurbopufferIndex struct {
// contains filtered or unexported fields
}
TurbopufferIndex is an indexed back by turbopuffer (https://turbopuffer.com).
func NewTurbopufferIndex ¶
func NewTurbopufferIndex( client *turbopuffer.Client, name string, distMetric DistanceMetric, fullTextAttribute *string, ) *TurbopufferIndex
NewTurbopufferIndex creates a new TurbopufferIndex from an API client and its name.
func (*TurbopufferIndex) Delete ¶
func (ti *TurbopufferIndex) Delete(ctx context.Context, selector DeleteSelector) error
func (*TurbopufferIndex) Query ¶
func (ti *TurbopufferIndex) Query(ctx context.Context, query Query) ([]ScoredDocument, error)