qdrant

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package qdrant — MultiStore routes operations across multiple physical Qdrant collections (Phase 4: physical collection isolation).

Each logical collection (engram_user, engram_agent_self, engram_reflection) maps to a dedicated *Store instance. This replaces the Phase 1-3 approach of using a single Qdrant collection with a `collection` payload field filter.

Package qdrant implements the memory.Store interface using Qdrant vector database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// URL is the Qdrant gRPC address in "host:port" format (default "localhost:6334").
	URL string
	// APIKey for Qdrant Cloud or authenticated deployments. Empty means no auth.
	APIKey string
	// UseTLS enables TLS for the gRPC connection. Required for Qdrant Cloud.
	UseTLS bool
	// CollectionName is the Qdrant collection to use (default "engram").
	CollectionName string
	// Dimension is the embedding vector size (default 1536).
	Dimension uint64
}

Config holds connection and collection settings for the Qdrant store.

type MultiStore added in v0.2.0

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

MultiStore implements memory.Store by routing operations to the appropriate physical Qdrant collection. It is safe for concurrent use.

func NewMultiStore added in v0.2.0

func NewMultiStore(stores map[string]*Store, defaultCol string) *MultiStore

NewMultiStore creates a MultiStore backed by the provided store map. defaultCol is the fallback collection for writes with an unset Collection field.

func (*MultiStore) Close added in v0.2.0

func (m *MultiStore) Close() error

Close closes all backing stores.

func (*MultiStore) Delete added in v0.2.0

func (m *MultiStore) Delete(ctx context.Context, ids []string) (int, error)

Delete removes memories by IDs from all physical collections. Qdrant delete is idempotent (no error for non-existent IDs).

func (*MultiStore) DeleteExpired added in v0.2.0

func (m *MultiStore) DeleteExpired(ctx context.Context) (int, error)

DeleteExpired removes expired memories from all physical collections.

func (*MultiStore) EnsureCollection added in v0.2.0

func (m *MultiStore) EnsureCollection(ctx context.Context) error

EnsureCollection initializes all physical collections.

func (*MultiStore) Insert added in v0.2.0

func (m *MultiStore) Insert(ctx context.Context, mem *memory.Memory, vector []float32) error

Insert routes the memory to its target physical collection. If mem.Collection is empty or unknown, it falls back to defaultCol and stamps mem.Collection so the payload reflects the actual physical collection.

func (*MultiStore) PerCollectionStats added in v0.2.0

func (m *MultiStore) PerCollectionStats(ctx context.Context) map[string]uint64

PerCollectionStats returns the point count for each physical collection. Errors for individual stores are silently skipped (partial results returned).

func (*MultiStore) Scroll added in v0.2.0

func (m *MultiStore) Scroll(ctx context.Context, opts memory.ScrollOptions) ([]memory.Memory, string, error)

Scroll returns memories from the targeted stores. When a single collection filter is present, full Qdrant-native pagination is supported. For multi-store fan-out (no filter or multiple collections), the implementation paginates through each store completely and returns all results without external pagination (next offset = "").

func (*MultiStore) Search added in v0.2.0

func (m *MultiStore) Search(ctx context.Context, vector []float32, opts memory.SearchOptions) ([]memory.ScoredMemory, error)

Search fans out to all stores matching the collection filter (or all stores if no collection filter is present). Results are merged and sorted by cosine score descending, then truncated to opts.Limit.

A single-store failure is logged as WARN and skipped (partial results) so one unavailable collection does not take down the entire search. The B2 X-Engram-Partial header will be added in Phase 5-B2 on top of this.

Fan-out uses a goroutine per store (currently 3). If future collections are added, continue using sync.WaitGroup/errgroup — do not loop-expand manually.

func (*MultiStore) SearchByIDs added in v0.2.0

func (m *MultiStore) SearchByIDs(ctx context.Context, ids []string) ([]memory.Memory, error)

SearchByIDs retrieves specific memories by their IDs from all stores. A single-store failure is logged as WARN and skipped (partial results) so a broken/empty store does not prevent lookups against healthy stores. Callers that need strict all-or-nothing semantics should check the length of the result against the input, but for existence-check uses (e.g. filterExistingIDs) partial results are preferable to a hard error.

func (*MultiStore) Stats added in v0.2.0

Stats returns aggregated statistics across all physical collections.

func (*MultiStore) Update added in v0.2.0

func (m *MultiStore) Update(ctx context.Context, id string, fields map[string]any) error

Update modifies payload fields of a memory across all physical collections. SetPayload on a non-existent ID is documented as a no-op, but the gRPC layer may surface a NotFound status when the point is not in a given collection. We ignore NotFound errors so the fan-out never fails because the point only lives in one of the three physical collections.

Resilience: we try every store regardless of errors. If at least one store succeeds we return nil immediately (the ID was found and updated). If all stores error we return nil when all errors are NotFound-type (the ID was already deleted — treat as an orphan success so callers move forward). Only when all stores error AND at least one error is a genuine non-NotFound error do we surface an error. This prevents a broken/empty store (e.g. engram_agent_self at 0 points) from blocking updates to the correct store.

func (*MultiStore) UpdateInCollection added in v0.2.0

func (m *MultiStore) UpdateInCollection(ctx context.Context, id string, fields map[string]any, sourceCollection string) error

UpdateInCollection updates payload fields only in the specified physical collection, avoiding the fan-out NotFound WARNs that occur when SetPayload targets all collections but the point exists in only one. Falls back to the full fan-out Update if sourceCollection is unknown.

type Store

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

Store implements memory.Store backed by Qdrant via gRPC. It is safe for concurrent use.

func New

func New(cfg Config) (*Store, error)

New creates a new Qdrant-backed Store. The caller must call EnsureCollection before performing any read/write operations.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying gRPC connection.

func (*Store) CollectionName added in v0.2.0

func (s *Store) CollectionName() string

CollectionName returns the Qdrant collection name this store is bound to.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, ids []string) (int, error)

Delete removes memories by IDs. Returns the number of successfully deleted items.

func (*Store) DeleteExpired

func (s *Store) DeleteExpired(ctx context.Context) (int, error)

DeleteExpired removes all memories whose valid_until > 0 AND valid_until < now. This is the physical cleanup counterpart to the soft-filter applied in Search/Scroll. Returns the number of deleted points (always == points matched, since Qdrant delete is idempotent and does not report per-point success).

func (*Store) DropCollection added in v0.2.0

func (s *Store) DropCollection(ctx context.Context) error

DropCollection deletes the Qdrant collection and all its data permanently.

func (*Store) EnsureCollection

func (s *Store) EnsureCollection(ctx context.Context) error

EnsureCollection creates the collection if it doesn't exist, and idempotently creates all payload indexes (safe to call on existing collections).

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, mem *memory.Memory, vector []float32) error

Insert stores a memory with its embedding vector.

func (*Store) Scroll

func (s *Store) Scroll(ctx context.Context, opts memory.ScrollOptions) ([]memory.Memory, string, error)

Scroll returns memories matching filters without requiring a query vector.

func (*Store) ScrollWithVectors added in v0.2.0

func (s *Store) ScrollWithVectors(ctx context.Context, opts memory.ScrollOptions) ([]memory.ScoredMemory, string, error)

ScrollWithVectors is like Scroll but includes the embedding vector for each returned memory (in ScoredMemory.Vector, Score=0). Used by migration tooling to copy points across physical collections without re-embedding.

func (*Store) Search

func (s *Store) Search(ctx context.Context, vector []float32, opts memory.SearchOptions) ([]memory.ScoredMemory, error)

Search returns scored memories matching the query vector. Results are ordered by raw cosine similarity (descending). Expired (valid_until > 0 && valid_until < now) and superseded memories are always excluded.

func (*Store) SearchByIDs

func (s *Store) SearchByIDs(ctx context.Context, ids []string) ([]memory.Memory, error)

SearchByIDs retrieves specific memories by their IDs.

func (*Store) Stats

func (s *Store) Stats(ctx context.Context) (*memory.CollectionStats, error)

Stats returns collection statistics.

func (*Store) Update

func (s *Store) Update(ctx context.Context, id string, fields map[string]any) error

Update modifies payload fields of an existing memory without re-embedding.

Jump to

Keyboard shortcuts

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