types

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const (
	L2                 DistanceFunction = "l2"
	COSINE             DistanceFunction = "cosine"
	IP                 DistanceFunction = "ip"
	DefaultTenant                       = "default_tenant"
	DefaultDatabase                     = "default_database"
	IDocuments         QueryEnum        = "documents"
	IEmbeddings        QueryEnum        = "embeddings"
	IMetadatas         QueryEnum        = "metadatas"
	IDistances         QueryEnum        = "distances"
	HNSWSpace                           = "hnsw:space"
	HNSWConstructionEF                  = "hnsw:construction_ef"
	HNSWBatchSize                       = "hnsw:batch_size"
	HNSWSyncThreshold                   = "hnsw:sync_threshold"
	HNSWM                               = "hnsw:M"
	HNSWSearchEF                        = "hnsw:search_ef"
	HNSWNumThreads                      = "hnsw:num_threads"
	HNSWResizeFactor                    = "hnsw:resize_factor"
	DefaultTimeout                      = 30 * time.Second
	EmbeddingsEpsilon                   = 1e-6
)

Variables

This section is empty.

Functions

func CompareEmbeddings

func CompareEmbeddings(embeddings []*Embedding, other []*Embedding) bool

func EmbedRecordsDefaultImpl

func EmbedRecordsDefaultImpl(e EmbeddingFunction, ctx context.Context, records []*Record, force bool) error

func ToAPIEmbeddings

func ToAPIEmbeddings(embeddings []*Embedding) []openapi.EmbeddingsInner

Types

type BasicAuthCredentialsProvider

type BasicAuthCredentialsProvider struct {
	Username string
	Password string
}

func NewBasicAuthCredentialsProvider

func NewBasicAuthCredentialsProvider(username, password string) *BasicAuthCredentialsProvider

func (*BasicAuthCredentialsProvider) Authenticate

func (b *BasicAuthCredentialsProvider) Authenticate(config *openapi.Configuration) error

type CollectionQueryBuilder

type CollectionQueryBuilder struct {
	QueryTexts      []string
	QueryEmbeddings []*Embedding
	Where           map[string]interface{}
	WhereDocument   map[string]interface{}
	NResults        int32
	Include         []QueryEnum
	Offset          int32
	Limit           int32
	Ids             []string
}

type CollectionQueryOption

type CollectionQueryOption func(*CollectionQueryBuilder) error

func WithIds

func WithIds(ids []string) CollectionQueryOption

func WithInclude

func WithInclude(include ...QueryEnum) CollectionQueryOption

func WithLimit

func WithLimit(limit int32) CollectionQueryOption

func WithNResults

func WithNResults(nResults int32) CollectionQueryOption

func WithOffset

func WithOffset(offset int32) CollectionQueryOption

func WithQueryEmbedding

func WithQueryEmbedding(queryEmbedding *Embedding) CollectionQueryOption

func WithQueryEmbeddings

func WithQueryEmbeddings(queryEmbeddings []*Embedding) CollectionQueryOption

func WithQueryText

func WithQueryText(queryText string) CollectionQueryOption

func WithQueryTexts

func WithQueryTexts(queryTexts []string) CollectionQueryOption

func WithWhere

func WithWhere(operation where.WhereOperation) CollectionQueryOption

func WithWhereDocumentMap

func WithWhereDocumentMap(where map[string]interface{}) CollectionQueryOption

func WithWhereMap

func WithWhereMap(where map[string]interface{}) CollectionQueryOption

type ConsistentHashEmbeddingFunction

type ConsistentHashEmbeddingFunction struct {
	// contains filtered or unexported fields
}

func (*ConsistentHashEmbeddingFunction) EmbedDocuments

func (e *ConsistentHashEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]*Embedding, error)

func (*ConsistentHashEmbeddingFunction) EmbedQuery

func (e *ConsistentHashEmbeddingFunction) EmbedQuery(_ context.Context, document string) (*Embedding, error)

func (*ConsistentHashEmbeddingFunction) EmbedRecords

func (e *ConsistentHashEmbeddingFunction) EmbedRecords(ctx context.Context, records []*Record, force bool) error

type CredentialsProvider

type CredentialsProvider interface {
	Authenticate(apiClient *openapi.Configuration) error
}

type DistanceFunction

type DistanceFunction string

func ToDistanceFunction

func ToDistanceFunction(str any) (DistanceFunction, error)

type Embedding

type Embedding struct {
	ArrayOfFloat32 *[]float32
	ArrayOfInt32   *[]int32
}

func NewEmbedding

func NewEmbedding(embeddings []interface{}) (*Embedding, error)

func NewEmbeddingFromAPI

func NewEmbeddingFromAPI(apiEmbedding openapi.EmbeddingsInner) *Embedding

func NewEmbeddingFromFloat32

func NewEmbeddingFromFloat32(embedding []float32) *Embedding

func NewEmbeddingFromInt32

func NewEmbeddingFromInt32(embedding []int32) *Embedding

func NewEmbeddings

func NewEmbeddings(embeddings []interface{}) ([]*Embedding, error)

func NewEmbeddingsFromFloat32

func NewEmbeddingsFromFloat32(embeddings [][]float32) []*Embedding

func NewEmbeddingsFromInt32

func NewEmbeddingsFromInt32(embeddings [][]int32) []*Embedding

func (*Embedding) Compare

func (e *Embedding) Compare(other *Embedding) bool

func (*Embedding) GetFloat32

func (e *Embedding) GetFloat32() *[]float32

func (*Embedding) GetInt32

func (e *Embedding) GetInt32() *[]int32

func (*Embedding) IsDefined

func (e *Embedding) IsDefined() bool

func (*Embedding) Len

func (e *Embedding) Len() int

func (*Embedding) String

func (e *Embedding) String() string

func (*Embedding) ToAPI

func (e *Embedding) ToAPI() openapi.EmbeddingsInner

type EmbeddingFunction

type EmbeddingFunction interface {
	// EmbedDocuments returns a vector for each text.
	EmbedDocuments(ctx context.Context, texts []string) ([]*Embedding, error)
	// EmbedQuery embeds a single text.
	EmbedQuery(ctx context.Context, text string) (*Embedding, error)
	EmbedRecords(ctx context.Context, records []*Record, force bool) error
}

func NewConsistentHashEmbeddingFunction

func NewConsistentHashEmbeddingFunction() EmbeddingFunction

type EmbeddingModel

type EmbeddingModel string

type IDGenerator

type IDGenerator interface {
	Generate(document string) string
}

type InvalidEmbeddingValueError

type InvalidEmbeddingValueError struct {
	Value interface{}
}

func (*InvalidEmbeddingValueError) Error

type InvalidMetadataValueError

type InvalidMetadataValueError struct {
	Key   string
	Value interface{}
}

func (*InvalidMetadataValueError) Error

func (e *InvalidMetadataValueError) Error() string

type Option

type Option func(*Record) error

func WithDocument

func WithDocument(document string) Option

func WithEmbedding

func WithEmbedding(embedding Embedding) Option

func WithID

func WithID(id string) Option

func WithMetadata

func WithMetadata(key string, value interface{}) Option

func WithMetadatas

func WithMetadatas(metadata map[string]interface{}) Option

func WithURI

func WithURI(uri string) Option

type QueryEnum

type QueryEnum string

type Record

type Record struct {
	ID        string
	Embedding Embedding
	Metadata  map[string]interface{}
	Document  string
	URI       string
	// contains filtered or unexported fields
}

func (*Record) Validate

func (r *Record) Validate() error

Validate checks if the record is valid

type RecordSet

type RecordSet struct {
	Records           []*Record
	IDGenerator       IDGenerator
	EmbeddingFunction EmbeddingFunction
}

func NewRecordSet

func NewRecordSet(opts ...RecordSetOption) (*RecordSet, error)

func (*RecordSet) BuildAndValidate

func (rs *RecordSet) BuildAndValidate(ctx context.Context) ([]*Record, error)

func (*RecordSet) GetDocuments

func (rs *RecordSet) GetDocuments() []string

func (*RecordSet) GetEmbeddings

func (rs *RecordSet) GetEmbeddings() []*Embedding

func (*RecordSet) GetIDs

func (rs *RecordSet) GetIDs() []string

func (*RecordSet) GetMetadatas

func (rs *RecordSet) GetMetadatas() []map[string]interface{}

func (*RecordSet) GetURIs

func (rs *RecordSet) GetURIs() []string

func (*RecordSet) Validate

func (rs *RecordSet) Validate() error

Validate the whole record set by calling record.Validate

func (*RecordSet) WithRecord

func (rs *RecordSet) WithRecord(recordOpts ...Option) *RecordSet

func (*RecordSet) WithRecords

func (rs *RecordSet) WithRecords(records []*Record) *RecordSet

type RecordSetOption

type RecordSetOption func(*RecordSet) error

func WithEmbeddingFunction

func WithEmbeddingFunction(embeddingFunction EmbeddingFunction) RecordSetOption

WithEmbeddingFunction sets the embedding function to be used for in place embedding.

func WithIDGenerator

func WithIDGenerator(idGenerator IDGenerator) RecordSetOption

type RerankingModel

type RerankingModel string

type SHA256Generator

type SHA256Generator struct{}

func NewSHA256Generator

func NewSHA256Generator() *SHA256Generator

func (*SHA256Generator) Generate

func (s *SHA256Generator) Generate(document string) string

type TokenAuthCredentialsProvider

type TokenAuthCredentialsProvider struct {
	Token  string
	Header TokenTransportHeader
}

func NewTokenAuthCredentialsProvider

func NewTokenAuthCredentialsProvider(token string, header TokenTransportHeader) *TokenAuthCredentialsProvider

func (*TokenAuthCredentialsProvider) Authenticate

func (t *TokenAuthCredentialsProvider) Authenticate(config *openapi.Configuration) error

type TokenTransportHeader

type TokenTransportHeader string
const (
	AuthorizationTokenHeader TokenTransportHeader = "Authorization"
	XChromaTokenHeader       TokenTransportHeader = "X-Chroma-Token"
)

type ULIDGenerator

type ULIDGenerator struct{}

func NewULIDGenerator

func NewULIDGenerator() *ULIDGenerator

func (*ULIDGenerator) Generate

func (u *ULIDGenerator) Generate(_ string) string

type UUIDGenerator

type UUIDGenerator struct{}

func NewUUIDGenerator

func NewUUIDGenerator() *UUIDGenerator

func (*UUIDGenerator) Generate

func (u *UUIDGenerator) Generate(_ string) string

Jump to

Keyboard shortcuts

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