qdrant

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PointIDTypeString int = 1
	PointIDTypeInt    int = 2
)

Variables

View Source
var (
	ErrInvalidPointID = errors.New("qdrant: invalid point id")

	ErrUnauthorized = errors.New("qdrant: unauthorized")
	ErrForbidden    = errors.New("qdrant: forbidden")
	ErrNotFound     = errors.New("qdrant: not found")
	ErrBadRequest   = errors.New("qdrant: bad request")
	ErrConflict     = errors.New("qdrant: conflict")
	ErrRateLimited  = errors.New("qdrant: rate limited")
	ErrServer       = errors.New("qdrant: server error")
)
View Source
var DefaultCollectionDefaults = Defaults{
	Distance: DistanceCosine,
	HNSW:     HNSWConfig{M: 16, EfConstruct: 128},
	Optim:    OptimizersConfig{DefaultSegmentNumber: 2},
}

Functions

func NewRESTClient

func NewRESTClient(cfg *ConnectionConfig) (*restClient, error)

Types

type CollectionConfig

type CollectionConfig struct {
	Vectors VectorsConfig `json:"vectors"`

	// Optional tuning
	HNSW       *HNSWConfig       `json:"hnsw_config,omitempty"`
	Optimizers *OptimizersConfig `json:"optimizers_config,omitempty"`

	// Distributed / storage knobs
	ShardNumber       int   `json:"shard_number,omitempty"`
	ReplicationFactor int   `json:"replication_factor,omitempty"`
	OnDiskPayload     *bool `json:"on_disk_payload,omitempty"`

	// Escape hatch for unsupported / future fields
	Extras map[string]any `json:"-"`
}

CollectionConfig represents the most commonly used Qdrant collection settings. It is opinionated but flexible.

Rule: - Typed fields for the common 80% - Extras for forward compatibility / advanced configs

func (*CollectionConfig) ApplyDefaults

func (c *CollectionConfig) ApplyDefaults(d Defaults) error

ApplyDefaults fills missing values without overriding user intent.

func (CollectionConfig) ToJSON

func (c CollectionConfig) ToJSON() (map[string]any, error)

ToJSON builds the final request body for Qdrant, merging typed config + Extras safely.

type CollectionInfo

type CollectionInfo struct {
	Status string `json:"status"` // can extend this struct if needed
}

type ConnectionConfig

type ConnectionConfig struct {
	BaseURL string // e.g. "http://localhost:6333"
	APIKey  string // optional

	Timeout         time.Duration // per-request hard timeout (http.Client)
	DialTimeout     time.Duration // TCP dial timeout
	IdleConnTimeout time.Duration // idle conn timeout

	// Retry
	RetryMaxAttempts int           // total attempts incl. first (default 3)
	RetryBaseDelay   time.Duration // default 150ms
	RetryMaxDelay    time.Duration // default 2s
	RetryJitter      float64       // 0..1 (default 0.2)
}

ConnectionConfig holds the configuration parameters required to establish a connection to a Qdrant server.

type CreateCollectionRequest

type CreateCollectionRequest struct {
	Collection string
	Config     CollectionConfig
}

type Defaults

type Defaults struct {
	Distance Distance
	HNSW     HNSWConfig
	Optim    OptimizersConfig
}

type DeletePointsRequest

type DeletePointsRequest struct {
	Collection string
	IDs        []PointID
	Wait       bool
}

type Distance

type Distance string
const (
	DistanceCosine    Distance = "Cosine"
	DistanceDot       Distance = "Dot"
	DistanceEuclid    Distance = "Euclid"
	DistanceManhattan Distance = "Manhattan"
)

type HNSWConfig

type HNSWConfig struct {
	M           int `json:"m,omitempty"`
	EfConstruct int `json:"ef_construct,omitempty"`
}

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type OptimizersConfig

type OptimizersConfig struct {
	DefaultSegmentNumber int `json:"default_segment_number,omitempty"`
}

type Point

type Point struct {
	ID      PointID        `json:"id"`
	Vector  []float32      `json:"vector,omitempty"`  // single-vector baseline
	Payload map[string]any `json:"payload,omitempty"` // Qdrant payload
}

type PointID

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

PointID supports string or integer IDs.

func PointIDInt

func PointIDInt(v int64) PointID

func PointIDString

func PointIDString(v string) PointID

func (PointID) MarshalJSON

func (id PointID) MarshalJSON() ([]byte, error)

func (*PointID) UnmarshalJSON

func (id *PointID) UnmarshalJSON(data []byte) error

type QdrantClientInterface

type QdrantClientInterface interface {
	Health(ctx context.Context) error

	UpsertPoints(ctx context.Context, req UpsertPointsRequest) error
	DeletePoints(ctx context.Context, req DeletePointsRequest) error
	Search(ctx context.Context, req SearchRequest) ([]ScoredPoint, error)

	// Collection management (minimal baseline)
	CreateCollection(ctx context.Context, req CreateCollectionRequest) error
	DeleteCollection(ctx context.Context, collection string) error
	GetCollectionInfo(ctx context.Context, collection string) (CollectionInfo, error)
}

QdrantClientInterface is a stable interface consumed by applications. It intentionally hides Qdrant SDK types and raw HTTP details.

type ScoredPoint

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

type SearchRequest

type SearchRequest struct {
	Collection     string
	Vector         []float32
	Limit          int
	Offset         int
	WithPayload    bool
	WithVector     bool
	ScoreThreshold *float32

	// Filter is raw Qdrant filter JSON. Keep flexible initially.
	Filter json.RawMessage
}

type UpsertPointsRequest

type UpsertPointsRequest struct {
	Collection string
	Points     []Point
	Wait       bool
}

type VectorParams

type VectorParams struct {
	Size     int      `json:"size"`
	Distance Distance `json:"distance"`
}

type VectorsConfig

type VectorsConfig struct {
	Single *VectorParams           `json:"-"`
	Named  map[string]VectorParams `json:"-"`
}

VectorsConfig supports either: - single unnamed vector - named vectors

func (VectorsConfig) MarshalJSON

func (v VectorsConfig) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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