qdrantkit

package
v11.3.24 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package qdrantkit provides an HTTP client for Qdrant vector database. Built on chassis call.Client for retry, circuit breaker, and OTel tracing.

Replaces custom Qdrant REST clients in equinox_graph, equinox_api, airborne, bizops, and agent-memory-benchmark.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is an HTTP client for Qdrant backed by call.Client.

func New

func New(cfg Config, opts ...Option) *Client

New creates a new Qdrant client.

func (*Client) Check

func (c *Client) Check() health.Check

Check returns a health.Check that pings Qdrant. Register with health.All().

func (*Client) CreateCollection

func (c *Client) CreateCollection(ctx context.Context, name string, cfg CollectionConfig) error

CreateCollection creates a collection with the given vector configuration. Returns nil if the collection already exists (HTTP 409).

func (*Client) CreatePayloadIndex

func (c *Client) CreatePayloadIndex(ctx context.Context, collection, field, fieldType string) error

CreatePayloadIndex creates a field index for filtered search performance. Returns nil if the index already exists.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, collection string, ids []string) error

Delete removes points by ID from a collection.

func (*Client) DeleteCollection

func (c *Client) DeleteCollection(ctx context.Context, name string) error

DeleteCollection deletes a collection. Returns nil if not found (HTTP 404).

func (*Client) GetCollection

func (c *Client) GetCollection(ctx context.Context, name string) (*CollectionInfo, error)

GetCollection returns info about a collection. Returns nil, nil if not found.

func (*Client) GetVectors

func (c *Client) GetVectors(ctx context.Context, collection string, ids []string) (map[string][]float32, error)

GetVectors fetches vectors by point IDs. Returns a map from ID to vector.

func (*Client) ListCollections

func (c *Client) ListCollections(ctx context.Context) ([]string, error)

ListCollections returns the names of all collections.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks Qdrant connectivity by listing collections.

func (*Client) Scroll

func (c *Client) Scroll(ctx context.Context, collection string, opts ScrollOptions) (*ScrollResult, error)

Scroll performs a paginated scan of points in a collection.

func (*Client) Search

func (c *Client) Search(ctx context.Context, collection string, vector []float32, opts SearchOptions) ([]ScoredPoint, error)

Search performs a nearest-neighbor vector search.

func (*Client) Upsert

func (c *Client) Upsert(ctx context.Context, collection string, points []Point) error

Upsert inserts or updates points in a collection. Uses wait=true so the call blocks until Qdrant confirms persistence.

type CollectionConfig

type CollectionConfig struct {
	Dimension int
	Distance  Distance
}

CollectionConfig defines parameters for creating a collection.

type CollectionInfo

type CollectionInfo struct {
	Status       string `json:"status"`
	VectorsCount int64  `json:"vectors_count"`
	PointsCount  int64  `json:"points_count"`
}

CollectionInfo contains details about a collection.

type Condition

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

Condition is a single filter predicate. Build with Match, Range, or HasID.

func HasID

func HasID(ids ...string) Condition

HasID creates a condition that matches specific point IDs.

func Match

func Match(key string, value any) Condition

Match creates an exact-match condition on a payload field.

func Range

func Range(key string, opts ...RangeOpt) Condition

Range creates a numeric range condition on a payload field.

func (Condition) MarshalJSON

func (c Condition) MarshalJSON() ([]byte, error)

MarshalJSON produces the Qdrant JSON representation of the condition.

type Config

type Config struct {
	BaseURL string        `env:"QDRANT_URL" default:"http://localhost:6333"`
	APIKey  string        `env:"QDRANT_API_KEY" required:"false"`
	Timeout time.Duration `env:"QDRANT_TIMEOUT" default:"10s"`
}

Config holds Qdrant connection settings.

type Distance

type Distance string

Distance is the vector similarity metric.

const (
	Cosine    Distance = "Cosine"
	Euclid    Distance = "Euclid"
	Dot       Distance = "Dot"
	Manhattan Distance = "Manhattan"
)

type Filter

type Filter struct {
	Must    []Condition `json:"must,omitempty"`
	Should  []Condition `json:"should,omitempty"`
	MustNot []Condition `json:"must_not,omitempty"`
}

Filter is a Qdrant filter with boolean clauses. Use Must, Should, or MustNot constructors, or build the struct directly for complex filters.

func Must

func Must(conds ...Condition) *Filter

Must returns a filter where all conditions must match.

func MustNot

func MustNot(conds ...Condition) *Filter

MustNot returns a filter where no conditions may match.

func Should

func Should(conds ...Condition) *Filter

Should returns a filter where at least one condition must match.

type Option

type Option func(*options)

Option configures a Client.

func WithCircuitBreaker

func WithCircuitBreaker(name string, threshold int, cooldown time.Duration) Option

WithCircuitBreaker protects the client with a named circuit breaker.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient replaces the underlying *http.Client used by call.Client.

func WithRetry

func WithRetry(maxAttempts int, baseDelay time.Duration) Option

WithRetry enables automatic retries for transient (5xx) errors using exponential backoff with jitter.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout overrides the default per-request timeout.

type Point

type Point struct {
	ID      string         `json:"id"`
	Vector  []float32      `json:"vector"`
	Payload map[string]any `json:"payload,omitempty"`
}

Point is a vector with ID and optional payload, used for upsert.

type RangeOpt

type RangeOpt func(*rangeSpec)

RangeOpt configures a range condition bound.

func Gt

func Gt(v float64) RangeOpt

Gt sets an exclusive lower bound.

func Gte

func Gte(v float64) RangeOpt

Gte sets an inclusive lower bound.

func Lt

func Lt(v float64) RangeOpt

Lt sets an exclusive upper bound.

func Lte

func Lte(v float64) RangeOpt

Lte sets an inclusive upper bound.

type ScoredPoint

type ScoredPoint struct {
	ID      string         `json:"id"`
	Score   float32        `json:"score"`
	Payload map[string]any `json:"payload,omitempty"`
	Vector  []float32      `json:"vector,omitempty"`
}

ScoredPoint is a search result with similarity score.

type ScrollOptions

type ScrollOptions struct {
	Limit       int
	Filter      *Filter
	Offset      *string
	WithPayload bool
	WithVector  bool
}

ScrollOptions configures a scroll (paginated scan) query.

type ScrollResult

type ScrollResult struct {
	Points         []ScoredPoint
	NextPageOffset *string
}

ScrollResult is a page from a scroll query.

type SearchOptions

type SearchOptions struct {
	Limit          int
	Filter         *Filter
	WithPayload    bool
	WithVector     bool
	ScoreThreshold *float32
}

SearchOptions configures a vector search.

Jump to

Keyboard shortcuts

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