qdrant

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

qdrant vector store

Experimental support for qdrant vector store.

If you wish to use it, you have to specify the DSN in the following format:

Insecure connections, qdrant cloud:

qdrant://[qdrant_cloud_api_key]@host:port

Secure encrypted connections, qdrant cloud:

qdrants://[qdrant_cloud_api_key]@host:port

If you want to run qdrant store by yourself, you don't need the qdrant cloud API key so you can specify the following DSN URL i.e. just omit the API key section:

qdrant://@host:port

Use a locally running qdrant instance (bound to localhost) over insecure connection:

go run ./... -dsn "qdrant://@0.0.0.0:6334"

You should be able to access your qdrant dashboard on http://0.0.0.0:6333/dashboard.

Documentation

Index

Constants

View Source
const (
	Scheme       = "qdrant"
	SecureScheme = "qdrants"
)
View Source
const (
	DefaultBaseURL = "http://localhost:6333"
)

Variables

View Source
var (
	ErrMissingVectorSize     = errors.New("ErrMissingVectorSize")
	ErrInvalidVectorSize     = errors.New("ErrInvalidVectorSize")
	ErrInvalidVectorDistance = errors.New("ErrInvalidVectorDistance")
)
View Source
var (
	ErrMissingDSN = errors.New("ErrMissingDSN")
	ErrInvalidDSN = errors.New("ErrInvalidDSN")
	ErrDBClosed   = errors.New("ErrDBClosed")
)

Functions

func Do

func Do(client *http.Client, req *http.Request) (*http.Response, error)

Do sends the HTTP request req using the client and returns the response.

func NewRequest

func NewRequest(ctx context.Context, method, url string, body io.Reader, opts ...ReqOption) (*http.Request, error)

NewRequest creates a new HTTP request from the provided parameters and returns it. If the passed in context is nil, it creates a new background context. If the provided body is nil, it gets initialized to bytes.Reader. By default the following headers are set: * Accept: application/json; charset=utf-8 If no Content-Type has been set via options it defaults to application/json.

Types

type APIError

type APIError struct {
	Time   float64 `json:"time"`
	Status struct {
		Error string `json:"error"`
	} `json:"status"`
	Result struct {
		OperationID int    `json:"operation_id"`
		Status      string `json:"status"`
	} `json:"result"`
}

APIError encodes qdrant API error.

func (APIError) Error

func (e APIError) Error() string

Error implements error interface.

type Action

type Action map[string]map[string]string

Action to take.

type Alias

type Alias struct {
	Name       string `json:"alias_name"`
	Collection string `json:"collection_name"`
}

Alias

type AliasActionReq

type AliasActionReq struct {
	// Actions to take on alias.
	Actions []Action `json:"actions"`
}

AliasActionReq is used to update collection aliases.

type AliasesResp

type AliasesResp struct {
	Time   float64 `json:"time"`
	Status string  `json:"status"`
	Result struct {
		Aliases []Alias `json:"aliases"`
	} `json:"result"`
}

AliasesResp

type DB

type DB struct {
	// DSN string
	DSN string
	// contains filtered or unexported fields
}

DB is qdrant DB store handle

func NewDB

func NewDB(dsn string) (*DB, error)

NewDB creates a new DB and returns it. TODO: figure out the DSN parsing, For now we support a very silly DSN parsing and expect the DSN to look like thi: qadrnt(s)://secret@host

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Open

func (db *DB) Open() (err error)

Open opens the database connection.

type HTTPClient

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

HTTPClient is qdrant HTTP API client.

func NewHTTPClient

func NewHTTPClient(opts ...Option) *HTTPClient

NewHTTPClient creates a new qdrant HTTP API client and returns it.

func (*HTTPClient) AliasList

func (c *HTTPClient) AliasList(ctx context.Context, collName string) (*AliasesResp, error)

AliasList action.

func (*HTTPClient) UpdateAliases

func (c *HTTPClient) UpdateAliases(ctx context.Context, actions []Action) error

UpdateAliases action (Create, Remove, Switch)

type Option

type Option func(*Options)

Option is functional graph option.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the API base URL.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the HTTP client.

type Options

type Options struct {
	APIKey     string
	BaseURL    string
	HTTPClient *http.Client
}

type ProvidersService

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

ProvidersService allows to store data in qdrant vector store.

func NewProvidersService

func NewProvidersService(db *DB) (*ProvidersService, error)

NewProvidersService creates an instance of ProvidersService and returns it.

func (*ProvidersService) AddProvider

func (p *ProvidersService) AddProvider(ctx context.Context, name string, md map[string]any) (*v1.Provider, error)

AddProvider creates a new provider and returns it. It creates a new qdrant collection and raturns the new provider. The collection name is the same as the UUID of the provider.

func (*ProvidersService) ComputeProviderProjections

func (p *ProvidersService) ComputeProviderProjections(ctx context.Context, uid string, proj v1.Projection) error

ComputeProviderProjections recomputes all projections from scratch for the provider with the given UID.

func (*ProvidersService) DropProviderEmbeddings

func (p *ProvidersService) DropProviderEmbeddings(ctx context.Context, uid string) error

DropProviderEmbeddings drops all provider embeddings from the store

func (*ProvidersService) GetProviderByUID

func (p *ProvidersService) GetProviderByUID(ctx context.Context, uid string) (*v1.Provider, error)

GetProviderByUID returns the provider with the given uid. NOTE: this does not populate metadata in v1.Provider because qdrant does not allow storing any metadata about the collections; only about the data stored in collections.

func (*ProvidersService) GetProviderEmbeddings

func (p *ProvidersService) GetProviderEmbeddings(ctx context.Context, uid string, filter v1.ProviderFilter) ([]v1.Embedding, v1.Page, error)

GetProviderEmbeddings returns embeddings for the provider with the given uid.

func (*ProvidersService) GetProviderProjections

func (p *ProvidersService) GetProviderProjections(ctx context.Context, uid string, filter v1.ProviderFilter) (map[v1.Dim][]v1.Embedding, v1.Page, error)

GetProviderProjections returns embeddings projections for the provider with the given uid.

func (*ProvidersService) GetProviders

func (p *ProvidersService) GetProviders(ctx context.Context, filter v1.ProviderFilter) ([]*v1.Provider, v1.Page, error)

GetProviders returns a list of providers filtered by filter. NOTE: this does not populate metadata in v1.Provider because qdrant does not allow storing any metadata about the collections; only about the data stored in collections.

func (*ProvidersService) UpdateProviderEmbeddings

func (p *ProvidersService) UpdateProviderEmbeddings(ctx context.Context, uid string, embeds []v1.Embedding, proj v1.Projection) ([]v1.Embedding, error)

UpdateProviderEmbeddings generates embeddings for the provider with the given uid.

type ReqOption

type ReqOption func(*http.Request)

ReqOption is http requestion functional option.

func WithBearer

func WithBearer(token string) ReqOption

WithBearer sets the Authorization header to the provided Bearer token.

Jump to

Keyboard shortcuts

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