dashvector

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 17 Imported by: 0

README

dashvector-sdk-go

GitHub release (latest by date)

MIT Licence GitHub code size

阿里云 向量检索服务 DashVector SDK for Go.

创建客户端

client := dashvector.NewClient(ctx)

创建Collection

_, _ = client.CreateServing(ctx, collectionName, 
    dashvector.WithDimension(4))

创建Partition

collection := client.GetCollection(collectionName)
_, _ = collection.CreateServing(ctx, partitionName)

创建Doc

// 可直接使用默认Partition
_, _ = collection.Insert(ctx,
    dashvector.WithDocument(
        dashvector.WithVector(0.1, 0.2, 0.3, 0.4),
    ))

// 也可使用自定义Partition
partition := collection.GetPartition(partitionName)
_, _ = partition.Insert(ctx,
    dashvector.WithDocument(
        dashvector.WithVector(0.1, 0.2, 0.3, 0.4),
    ))

检索Doc

// 可直接使用默认Partition
queryResponse, _ := collection.Query(ctx,
    dashvector.QueryWithVector(0.1, 0.2, 0.3, 0.4),
    dashvector.QueryWithTopk(10),
    dashvector.QueryWithIncludeVector(true))

// 也可使用自定义Partition
partition := collection.GetPartition(partitionName)
queryResponse, _ := partition.Query(ctx,
    dashvector.QueryWithVector(0.1, 0.2, 0.3, 0.4),
    dashvector.QueryWithTopk(10),
    dashvector.QueryWithIncludeVector(true))

Documentation

Index

Constants

View Source
const QuantizeTypeInt8 = "DT_VECTOR_INT8"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Create(ctx context.Context, collectionName string, configs ...CollectionConfig) (Response, error)
	Desc(ctx context.Context, collectionName string) (CollectionDescResponse, error)
	List(ctx context.Context) (CollectionListResponse, error)
	Stats(ctx context.Context, collectionName string) (CollectionStatsResponse, error)
	Delete(ctx context.Context, collectionName string) (Response, error)
	CreateServing(ctx context.Context, collectionName string, configs ...CollectionConfig) (Response, error)
	GetCollection(collectionName string) Collection
}

func NewClient

func NewClient(ctx context.Context, clientName ...string) Client

type Collection

type Collection interface {
	Create(ctx context.Context, partitionName string) (Response, error)
	Desc(ctx context.Context, partitionName string) (PartitionDescResponse, error)
	List(ctx context.Context) (PartitionListResponse, error)
	Stats(ctx context.Context, partitionName string) (PartitionStatsResponse, error)
	Delete(ctx context.Context, partitionName string) (Response, error)
	CreateServing(ctx context.Context, partitionName string) (Response, error)
	GetPartition(partitionName ...string) Partition
	Partition
}

type CollectionConfig

type CollectionConfig func(*collectionCreateRequest)

func WithDataType

func WithDataType(dataType DataType) CollectionConfig

func WithDimension

func WithDimension(dimension int) CollectionConfig

func WithExtraParams

func WithExtraParams(configs ...ExtraParamsConfig) CollectionConfig

func WithFieldSchema

func WithFieldSchema(name string, fieldType FieldType) CollectionConfig

func WithMetric

func WithMetric(metric Metric) CollectionConfig

func WithVectorSchema

func WithVectorSchema(name string, dimension int, configs ...VectorSchemaConfig) CollectionConfig

type CollectionDescResponse

type CollectionDescResponse interface {
	Response
	GetOutput() CollectionMeta
}

type CollectionListResponse

type CollectionListResponse interface {
	Response
	GetOutput() []string
}

type CollectionMeta

type CollectionMeta interface {
	GetName() string
	GetDimension() int
	GetDataType() DataType
	GetMetric() Metric
	GetStatus() Status
	GetFieldsSchema() map[string]FieldType
	GetVectorsSchema() map[string]VectorSchema
	GetPartitionStatus() map[string]Status
}

type CollectionStats

type CollectionStats interface {
	GetTotalDocCount() int64
	GetIndexCompleteness() float64
	GetPartitions() map[string]PartitionStats
}

type CollectionStatsResponse

type CollectionStatsResponse interface {
	Response
	GetOutput() CollectionStats
}

type DataType

type DataType string
const (
	DataTypeFloat DataType = "FLOAT"
	DataTypeInt   DataType = "INT"
)

type Doc

type Doc interface {
	GetId() string
	GetVector() []float32
	GetVectors() map[string][]float32
	GetSparseVector() map[int32]float32
	GetFields() map[string]any
	GetScore() float32
}

type DocOp

type DocOp string
const (
	DocOpInsert DocOp = "insert"
	DocOpUpdate DocOp = "update"
	DocOpUpsert DocOp = "upsert"
	DocOpDelete DocOp = "delete"
)

type DocOpResult

type DocOpResult interface {
	GetId() string
	GetCode() int
	GetMessage() string
	GetDocOp() DocOp
}

type DocumentConfig

type DocumentConfig func(*doc)

func WithField

func WithField(name string, value any) DocumentConfig

func WithId

func WithId(id string) DocumentConfig

func WithSchemaVector

func WithSchemaVector(name string, vector ...float32) DocumentConfig

func WithSparseVector

func WithSparseVector(key int32, value float32) DocumentConfig

func WithVector

func WithVector(vector ...float32) DocumentConfig

type DocumentsConfig

type DocumentsConfig func(*documentsWriteRequest, func(*doc) bool)

func WithDocument

func WithDocument(configs ...DocumentConfig) DocumentsConfig

type DocumentsGroupQueryConfig

type DocumentsGroupQueryConfig func(*documentsGroupQueryRequest)

func GroupQueryWithCount

func GroupQueryWithCount(groupCount int) DocumentsGroupQueryConfig

func GroupQueryWithFilter

func GroupQueryWithFilter(filter string) DocumentsGroupQueryConfig

func GroupQueryWithId

func GroupQueryWithId(id string) DocumentsGroupQueryConfig

func GroupQueryWithIncludeVector

func GroupQueryWithIncludeVector(includeVector bool) DocumentsGroupQueryConfig

func GroupQueryWithOutputFields

func GroupQueryWithOutputFields(fields ...string) DocumentsGroupQueryConfig

func GroupQueryWithSchemaVector

func GroupQueryWithSchemaVector(vectorField string) DocumentsGroupQueryConfig

func GroupQueryWithSparseVector

func GroupQueryWithSparseVector(key int32, value float32) DocumentsGroupQueryConfig

func GroupQueryWithTopk

func GroupQueryWithTopk(groupTopk int) DocumentsGroupQueryConfig

func GroupQueryWithVector

func GroupQueryWithVector(vector ...float32) DocumentsGroupQueryConfig

type DocumentsGroupQueryResponse

type DocumentsGroupQueryResponse interface {
	Response
	GetOutput() []Group
}

type DocumentsQueryConfig

type DocumentsQueryConfig func(*documentsQueryRequest)

func QueryWithFilter

func QueryWithFilter(filter string) DocumentsQueryConfig

func QueryWithId

func QueryWithId(id string) DocumentsQueryConfig

func QueryWithIncludeVector

func QueryWithIncludeVector(includeVector bool) DocumentsQueryConfig

func QueryWithOutputFields

func QueryWithOutputFields(fields ...string) DocumentsQueryConfig

func QueryWithRrfRanker

func QueryWithRrfRanker(rankConstant int) DocumentsQueryConfig

func QueryWithSchemaVector

func QueryWithSchemaVector(name string, vector []float32, configs ...VectorQueryConfig) DocumentsQueryConfig

func QueryWithSparseVector

func QueryWithSparseVector(key int32, value float32) DocumentsQueryConfig

func QueryWithTopk

func QueryWithTopk(topk int) DocumentsQueryConfig

func QueryWithVector

func QueryWithVector(vector ...float32) DocumentsQueryConfig

func QueryWithVectorQueryParam

func QueryWithVectorQueryParam(configs ...VectorQueryConfig) DocumentsQueryConfig

func QueryWithWeightedRanker

func QueryWithWeightedRanker(weights map[string]float32) DocumentsQueryConfig

type DocumentsQueryResponse

type DocumentsQueryResponse interface {
	Response
	GetOutput() []Doc
	GetUsage() ResponseUsage
}

type DocumentsReadResponse

type DocumentsReadResponse interface {
	Response
	GetOutput() map[string]Doc
	GetUsage() ResponseUsage
}

type DocumentsWriteResponse

type DocumentsWriteResponse interface {
	Response
	GetOutput() []DocOpResult
	GetUsage() ResponseUsage
}

type ExtraParamsConfig

type ExtraParamsConfig func(*extraParams)

func WithAutoId

func WithAutoId(autoId string) ExtraParamsConfig

func WithQuantizeType

func WithQuantizeType(quantizeType QuantizeType) ExtraParamsConfig

type FieldType

type FieldType string
const (
	FieldTypeBool   FieldType = "BOOL"
	FieldTypeString FieldType = "STRING"
	FieldTypeInt    FieldType = "INT"
	FieldTypeFloat  FieldType = "FLOAT"
)

type Group

type Group interface {
	GetGroupId() string
	GetDocs() []Doc
}

type Metric

type Metric string
const (
	MetricEuclidean  Metric = "euclidean"
	MetricDotproduct Metric = "dotproduct"
	MetricCosine     Metric = "cosine"
)

type PartitionDescResponse

type PartitionDescResponse interface {
	Response
	GetOutput() Status
}

type PartitionListResponse

type PartitionListResponse interface {
	Response
	GetOutput() []string
}

type PartitionStats

type PartitionStats interface {
	GetTotalDocCount() int64
}

type PartitionStatsResponse

type PartitionStatsResponse interface {
	Response
	GetOutput() PartitionStats
}

type QuantizeType

type QuantizeType string

type Response

type Response interface {
	GetCode() int
	GetMessage() string
	GetRequestId() string
}

type ResponseUsage

type ResponseUsage interface {
	GetReadUnits() int
	GetWriteUnits() int
}

type Status

type Status string
const (
	StatusInitialized Status = "INITIALIZED"
	StatusServing     Status = "SERVING"
	StatusDropping    Status = "DROPPING"
	StatusError       Status = "ERROR"
)

type VectorQueryConfig

type VectorQueryConfig func(*vectorQuery)

func QueryWithEf

func QueryWithEf(ef int) VectorQueryConfig

func QueryWithLinear

func QueryWithLinear(isLinear bool) VectorQueryConfig

func QueryWithNumCandidates

func QueryWithNumCandidates(numCandidates int) VectorQueryConfig

func QueryWithRadius

func QueryWithRadius(radius float32) VectorQueryConfig

type VectorSchema

type VectorSchema interface {
	GetDimension() int
	GetDataType() DataType
	GetMetric() Metric
	GetQuantizeType() QuantizeType
}

type VectorSchemaConfig

type VectorSchemaConfig func(*vectorSchemaParam)

func WithVectorDataType

func WithVectorDataType(dataType DataType) VectorSchemaConfig

func WithVectorMetric

func WithVectorMetric(metric Metric) VectorSchemaConfig

func WithVectorQuantizeType

func WithVectorQuantizeType(quantizeType QuantizeType) VectorSchemaConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL