milvus

package
v0.9.21 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldDocumentID     = "document_id"
	FieldText           = "text"
	FieldContent        = "content"
	FieldImage          = "image"
	FieldImageData      = "image_data"
	FieldURL            = "url"
	FieldEmbedding      = "embedding"
	FieldMetadata       = "metadata"
	FieldCreatedAt      = "created_at"
	FieldUpdatedAt      = "updated_at"
	FieldImageThumbnail = "image_thumbnail" // External storage: thumbnail (base64, <47KB)
	FieldImageURL       = "image_url"       // External storage: full image URL (S3/MinIO)
	FieldImageMetadata  = "image_metadata"  // External storage: image metadata (JSON)
)

Collection field names (standardized across all collections)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter wraps the Milvus client to implement the vectordb.VectorDBClient interface

func NewAdapter

func NewAdapter(config *vectordb.Config) (*Adapter, error)

NewAdapter creates a new Milvus adapter from the vectordb.Config

func (*Adapter) Close added in v0.8.1

func (a *Adapter) Close() error

Close closes the Milvus adapter and cleans up resources

func (*Adapter) CreateDocument

func (a *Adapter) CreateDocument(ctx context.Context, collectionName string, document *vectordb.Document) error

CreateDocument creates a new document in the specified collection

func (*Adapter) CreateDocuments

func (a *Adapter) CreateDocuments(ctx context.Context, collectionName string, documents []*vectordb.Document) error

CreateDocuments creates multiple documents in batch

func (*Adapter) GetDefaultSchema

func (a *Adapter) GetDefaultSchema(schemaType vectordb.SchemaType, collectionName string) *vectordb.CollectionSchema

GetDefaultSchema returns a default schema for the given type

func (*Adapter) SearchHybrid

func (a *Adapter) SearchHybrid(ctx context.Context, collectionName, query string, opts *vectordb.QueryOptions) ([]*vectordb.QueryResult, error)

SearchHybrid performs hybrid search combining vector and keyword search

func (*Adapter) SearchSemantic

func (a *Adapter) SearchSemantic(ctx context.Context, collectionName, query string, opts *vectordb.QueryOptions) ([]*vectordb.QueryResult, error)

SearchSemantic performs semantic search using Milvus vector search

func (*Adapter) UpdateDocument

func (a *Adapter) UpdateDocument(ctx context.Context, collectionName string, document *vectordb.Document) error

UpdateDocument updates an existing document (delete + insert)

func (*Adapter) UpdateSchema

func (a *Adapter) UpdateSchema(ctx context.Context, collectionName string, schema *vectordb.CollectionSchema) error

UpdateSchema updates a collection's schema

func (*Adapter) ValidateSchema

func (a *Adapter) ValidateSchema(schema *vectordb.CollectionSchema) error

ValidateSchema validates a schema definition

type Client

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

Client wraps the Milvus client with vector database functionality

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient creates a new Milvus client

func (*Client) Close

func (c *Client) Close() error

Close closes the Milvus client connection

func (*Client) CollectionExists

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

CollectionExists checks if a collection exists

func (*Client) CreateCollection

func (c *Client) CreateCollection(ctx context.Context, name string, schema *vectordb.CollectionSchema) error

CreateCollection creates a new Milvus collection with explicit schema

func (*Client) DeleteCollection

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

DeleteCollection deletes a collection and all its documents

func (*Client) DeleteDocument

func (c *Client) DeleteDocument(ctx context.Context, collectionName, documentID string) error

DeleteDocument deletes a document by ID

func (*Client) DeleteDocuments

func (c *Client) DeleteDocuments(ctx context.Context, collectionName string, documentIDs []string) error

DeleteDocuments deletes multiple documents by IDs

func (*Client) DeleteDocumentsByMetadata

func (c *Client) DeleteDocumentsByMetadata(ctx context.Context, collectionName string, metadata map[string]interface{}) error

DeleteDocumentsByMetadata deletes documents matching metadata criteria

func (*Client) GetCollectionCount

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

GetCollectionCount returns the number of documents in a collection

func (*Client) GetDocument

func (c *Client) GetDocument(ctx context.Context, collectionName, documentID string) (*vectordb.Document, error)

GetDocument retrieves a document by ID

func (*Client) GetSchema

func (c *Client) GetSchema(ctx context.Context, name string) (*vectordb.CollectionSchema, error)

GetSchema returns the schema information for a collection

func (*Client) Health

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

Health checks the health of the Milvus instance

func (*Client) ListCollections

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

ListCollections returns a list of all collections

func (*Client) ListDocuments

func (c *Client) ListDocuments(ctx context.Context, collectionName string, limit, offset int) ([]*vectordb.Document, error)

ListDocuments returns a paginated list of documents from a collection

func (*Client) SearchBM25

func (c *Client) SearchBM25(ctx context.Context, collectionName, query string, opts *vectordb.QueryOptions) ([]*vectordb.QueryResult, error)

SearchBM25 performs keyword-based search using Milvus BM25 (Milvus 2.4+)

func (*Client) SearchByMetadata

func (c *Client) SearchByMetadata(ctx context.Context, collectionName string, metadata map[string]interface{}, opts *vectordb.QueryOptions) ([]*vectordb.QueryResult, error)

SearchByMetadata searches documents by metadata fields

type Config

type Config struct {
	// Connection settings
	Address  string // Milvus server address (e.g., "localhost:19530")
	Username string // Username for authentication (optional)
	Password string // Password for authentication (optional)
	APIKey   string // API key/token for Zilliz Cloud (optional)
	Database string // Database name (default: "default")
	Timeout  int    // Timeout in seconds for operations (default: 10)

	// Vector search settings
	VectorDimensions int    // Embedding vector dimensions (e.g., 1536 for OpenAI)
	SimilarityMetric string // Similarity metric: "L2", "IP" (inner product), or "COSINE"
}

Config holds Milvus client configuration

type Factory

type Factory struct{}

Factory implements the ClientFactory interface for Milvus

func NewFactory

func NewFactory() *Factory

NewFactory creates a new Milvus factory

func (*Factory) CreateClient

func (f *Factory) CreateClient(config *vectordb.Config) (vectordb.VectorDBClient, error)

CreateClient creates a new Milvus client

func (*Factory) GetSupportedTypes

func (f *Factory) GetSupportedTypes() []vectordb.VectorDBType

GetSupportedTypes returns the list of supported database types

func (*Factory) ValidateConfig

func (f *Factory) ValidateConfig(config *vectordb.Config) error

ValidateConfig validates the configuration for Milvus

Jump to

Keyboard shortcuts

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