db

package
v0.0.0-...-687952b Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InternalDocName       = "_m_doc"
	InternalIdName        = "_m_id"
	InternalEmbeddingName = "_m_embedding"
	MetaPersistBatch      = 1000
)
View Source
const CohereMaxTexts = 96
View Source
const CohereTextMaxLen = 512
View Source
const HnswGrowSize = 1000

Variables

View Source
var (
	ErrCollectionNotFound  = errors.New("collection not found")
	ErrFieldLengthMismatch = errors.New("documents and metadatas are mismatch")
	ErrMetaCorrupted       = errors.New("meta corrupted")
)
View Source
var ErrTooManyTexts error = errors.New("too many texts")

Functions

func Convert2Float32

func Convert2Float32[T any](embedding []T) []float32

func StartEmbeddedPostgres

func StartEmbeddedPostgres(cfg *config.Config) (*postgres.EmbeddedPostgres, error)

func StartFerretDB

func StartFerretDB(database *postgres.EmbeddedPostgres, cfg *config.Config) (*ferretdb.FerretDB, error)

Types

type CohereEmbedding

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

func NewCohereEmbedding

func NewCohereEmbedding(cfg *config.CohereCfg) (*CohereEmbedding, error)

func (*CohereEmbedding) GetEmbedding

func (c *CohereEmbedding) GetEmbedding(texts []string) ([][]float32, error)

type Collection

type Collection struct {
	*mongo.Collection
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection(ctx context.Context, meta *Meta, collection *mongo.Collection, name string, cfg *config.Config) (*Collection, error)

func (*Collection) Insert

func (c *Collection) Insert(data *Data) error

func (*Collection) Query

func (c *Collection) Query(document string, k int, filter interface{}) ([]bson.M, error)

type Data

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

func NewData

func NewData() *Data

func (*Data) Documents

func (d *Data) Documents(documents []string) *Data

func (*Data) Metadatas

func (d *Data) Metadatas(metadatas []bson.M) *Data

type HNSWIndex

type HNSWIndex struct {
	*hnsw.Hnsw
	// contains filtered or unexported fields
}

func NewHNSWIndex

func NewHNSWIndex(cfg *config.HNSWCfg, dim int) *HNSWIndex

func NewHNSWIndexFromFile

func NewHNSWIndexFromFile(file string, size, id uint32) (*HNSWIndex, error)

func (*HNSWIndex) Add

func (h *HNSWIndex) Add(point hnsw.Point, id uint32)

func (*HNSWIndex) ID

func (h *HNSWIndex) ID() uint32

func (*HNSWIndex) Size

func (h *HNSWIndex) Size() uint32

type Kaer

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

func CreateKaer

func CreateKaer(cfg *config.Config) (*Kaer, error)

func (*Kaer) Close

func (k *Kaer) Close() error

func (*Kaer) CreateCollection

func (k *Kaer) CreateCollection(ctx context.Context, name string) (*Collection, error)

func (*Kaer) DropCollection

func (k *Kaer) DropCollection(ctx context.Context, name string) error

func (*Kaer) GetCollection

func (k *Kaer) GetCollection(ctx context.Context, name string) (*Collection, error)

type Meta

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

func NewMeta

func NewMeta(client *mongo.Client) *Meta

func (*Meta) Drop

func (m *Meta) Drop(ctx context.Context, collectionName string) error

func (*Meta) Read

func (m *Meta) Read(ctx context.Context, collectionName string) (metaInfo, error)

func (*Meta) Write

func (m *Meta) Write(ctx context.Context, info metaInfo) error

Jump to

Keyboard shortcuts

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