Documentation
¶
Overview ¶
Package vector defines the Vector building-block contract used by Dapr's vector.proto runtime API. Components implement Vector to store, retrieve and query pre-embedded dense vectors.
Index ¶
- type BatchQueryRequest
- type BatchQueryResponse
- type BatchQueryResult
- type CreateCollectionRequest
- type DeleteCollectionRequest
- type DeleteRequest
- type DeleteResponse
- type DistanceMetric
- type GetCollectionRequest
- type GetCollectionResponse
- type GetRequest
- type GetResponse
- type ListCollectionsRequest
- type ListCollectionsResponse
- type Match
- type Metadata
- type QueryRequest
- type QueryResponse
- type Record
- type UpsertRequest
- type UpsertResponse
- type Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchQueryRequest ¶
type BatchQueryRequest struct {
Collection string
Queries []QueryRequest
Metadata map[string]string
}
BatchQueryRequest issues multiple queries against the same collection.
type BatchQueryResponse ¶
type BatchQueryResponse struct {
Results []BatchQueryResult
}
BatchQueryResponse holds one result per query, in request order.
type BatchQueryResult ¶
type BatchQueryResult struct {
Response *QueryResponse
// Error is a gRPC status error carrying a canonical, non-OK code.
Error error
}
BatchQueryResult is the outcome of one query in a batch. Exactly one of Response or Error is set.
type CreateCollectionRequest ¶
type CreateCollectionRequest struct {
Collection string
// Component-specific settings such as index parameters.
Metadata map[string]string
// Dimensions is the required length of every stored vector.
Dimensions uint32
// Metric is the collection's distance metric. Unspecified selects the
// component's documented default.
Metric DistanceMetric
}
CreateCollectionRequest creates a new vector collection.
type DeleteCollectionRequest ¶
DeleteCollectionRequest deletes an existing collection.
type DeleteRequest ¶
type DeleteRequest struct {
Collection string
IDs []string
Metadata map[string]string
Options search.IndexingOptions
}
DeleteRequest deletes vectors by id. IDs that do not exist are not an error.
type DeleteResponse ¶
type DeleteResponse struct {
// Always IndexAckQueued or IndexAckCompleted on success.
Ack search.IndexAck
}
DeleteResponse is the result of a Delete call.
type DistanceMetric ¶
type DistanceMetric int32
DistanceMetric determines how scores and score thresholds are interpreted. Mirrors vector.proto DistanceMetric.
const ( // DistanceMetricUnspecified selects the component's default metric on // CreateCollection and the collection's configured metric on Query. DistanceMetricUnspecified DistanceMetric = 0 // DistanceMetricCosine is cosine similarity in [-1, 1]. Higher is better. DistanceMetricCosine DistanceMetric = 1 // DistanceMetricDotProduct is unbounded dot-product similarity. Higher is // better. DistanceMetricDotProduct DistanceMetric = 2 // DistanceMetricEuclidean is Euclidean distance in [0, +inf). Lower is // better. DistanceMetricEuclidean DistanceMetric = 3 )
func (DistanceMetric) HigherIsBetter ¶
func (m DistanceMetric) HigherIsBetter() bool
HigherIsBetter reports whether higher scores indicate closer matches for the metric.
type GetCollectionRequest ¶
GetCollectionRequest gets an existing collection.
type GetCollectionResponse ¶
type GetCollectionResponse struct {
Collection string
// Approximate number of records. Providers that cannot supply this value
// efficiently may return 0.
RecordCount uint64
Properties map[string]string
Dimensions uint32
// Metric is the effective metric and is always concrete.
Metric DistanceMetric
}
GetCollectionResponse describes an existing collection.
type GetRequest ¶
type GetRequest struct {
Collection string
IDs []string
IncludeValues bool
Metadata map[string]string
}
GetRequest fetches vectors by id.
type GetResponse ¶
type GetResponse struct {
Records []Record
}
GetResponse is the result of a Get call. Records are returned in request order; records that are not found are omitted.
type ListCollectionsRequest ¶
ListCollectionsRequest lists collections in the store.
type ListCollectionsResponse ¶
type ListCollectionsResponse struct {
Collections []string
}
ListCollectionsResponse lists collections in the store.
type Match ¶
type Match struct {
Record Record
// Score is the unnormalized value of the effective metric.
Score float64
}
Match is a single match returned from a vector query.
type QueryRequest ¶
type QueryRequest struct {
Collection string
// Vector is the query vector. Only its Values are read.
Vector *Record
ByID string
TopK uint32
Filter map[string]any
IncludeValues bool
IncludePayload bool
// Metric selects how scores are interpreted. Unspecified uses the
// collection's configured metric.
Metric DistanceMetric
// ScoreThreshold is an inclusive, unnormalized cutoff.
ScoreThreshold *float64
Metadata map[string]string
}
QueryRequest is a single vector query. Exactly one of Vector or ByID is set.
type QueryResponse ¶
type QueryResponse struct {
Matches []Match
// Effective metric used for scores. Always concrete.
Metric DistanceMetric
}
QueryResponse is the result of a single Query call.
type Record ¶
type Record struct {
ID string
// Values is the dense vector. Its length must equal the collection's
// dimensions.
Values []float32
// Payload is opaque caller data stored with the record and returned
// unchanged. It is not filterable.
Payload []byte
// Metadata holds structured, filterable attributes addressed by the
// portable filter DSL.
Metadata map[string]any
}
Record is a single dense vector record.
type UpsertRequest ¶
type UpsertRequest struct {
Collection string
Records []Record
Metadata map[string]string
Options search.IndexingOptions
}
UpsertRequest is a keyed upsert of vector records. Every record has a non-empty ID that is unique within the request.
type UpsertResponse ¶
type UpsertResponse struct {
// Item-specific failures known at the acknowledgement boundary.
FailedItems []search.FailedItem
// Always IndexAckQueued or IndexAckCompleted on success.
Ack search.IndexAck
}
UpsertResponse is the result of an Upsert call.
type Vector ¶
type Vector interface {
metadata.ComponentWithMetadata
// Init is called once per component instance.
Init(ctx context.Context, meta Metadata) error
// Collection lifecycle.
CreateCollection(ctx context.Context, req *CreateCollectionRequest) error
GetCollection(ctx context.Context, req *GetCollectionRequest) (*GetCollectionResponse, error)
ListCollections(ctx context.Context, req *ListCollectionsRequest) (*ListCollectionsResponse, error)
DeleteCollection(ctx context.Context, req *DeleteCollectionRequest) error
// Vector data operations.
Upsert(ctx context.Context, req *UpsertRequest) (*UpsertResponse, error)
Get(ctx context.Context, req *GetRequest) (*GetResponse, error)
Delete(ctx context.Context, req *DeleteRequest) (*DeleteResponse, error)
// Query.
Query(ctx context.Context, req *QueryRequest) (*QueryResponse, error)
BatchQuery(ctx context.Context, req *BatchQueryRequest) (*BatchQueryResponse, error)
io.Closer
}
Vector is the Vector building-block component contract. Method shapes mirror the alpha1 RPCs in dapr/proto/runtime/v1/vector.proto using Go-native types.
Errors returned by components SHOULD be gRPC status errors carrying a canonical code. Other errors are reported to callers as INTERNAL.