elasticsearch

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: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 Elasticsearch client to implement the vectordb.VectorDBClient interface

func NewAdapter

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

NewAdapter creates a new Elasticsearch adapter from vectordb.Config

func (*Adapter) Close added in v0.8.1

func (a *Adapter) Close(ctx context.Context) error

Close closes the Elasticsearch adapter and cleans up resources

func (*Adapter) CollectionExists

func (a *Adapter) CollectionExists(ctx context.Context, name string) (bool, error)

CollectionExists checks if an Elasticsearch index exists

func (*Adapter) CreateCollection

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

CreateCollection creates a new Elasticsearch index with vector field mappings

func (*Adapter) CreateDocument

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

CreateDocument creates a single document in the specified index

func (*Adapter) CreateDocuments

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

CreateDocuments creates multiple documents in batch using BulkIndexer

func (*Adapter) DeleteCollection

func (a *Adapter) DeleteCollection(ctx context.Context, name string) error

DeleteCollection deletes an Elasticsearch index

func (*Adapter) DeleteDocument

func (a *Adapter) DeleteDocument(ctx context.Context, collectionName, documentID string) error

DeleteDocument deletes a document by ID

func (*Adapter) DeleteDocuments

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

DeleteDocuments deletes multiple documents by IDs

func (*Adapter) DeleteDocumentsByMetadata

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

DeleteDocumentsByMetadata deletes documents matching metadata criteria

func (*Adapter) GetCollectionCount

func (a *Adapter) GetCollectionCount(ctx context.Context, name string) (int64, error)

GetCollectionCount returns the number of documents in an Elasticsearch index

func (*Adapter) GetDefaultSchema

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

func (*Adapter) GetDocument

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

GetDocument retrieves a document by ID

func (*Adapter) GetSchema

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

GetSchema retrieves the index mappings and converts to CollectionSchema

func (*Adapter) ListCollections

func (a *Adapter) ListCollections(ctx context.Context) ([]vectordb.CollectionInfo, error)

ListCollections returns a list of all Elasticsearch indices

func (*Adapter) ListDocuments

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

ListDocuments returns a paginated list of documents

func (*Adapter) SearchBM25

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

SearchBM25 performs a full-text search using BM25

func (*Adapter) SearchByMetadata

func (a *Adapter) SearchByMetadata(ctx context.Context, collectionName string, metadata map[string]interface{}, options *vectordb.QueryOptions) ([]*vectordb.QueryResult, error)

SearchByMetadata searches documents by metadata fields

func (*Adapter) SearchHybrid

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

SearchHybrid performs a hybrid search combining semantic and BM25 results

func (*Adapter) SearchSemantic

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

SearchSemantic performs a semantic (vector) search using kNN

func (*Adapter) UpdateDocument

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

UpdateDocument updates an existing document

func (*Adapter) UpdateSchema

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

UpdateSchema updates the index mappings

func (*Adapter) ValidateSchema

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

type Client

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

Client wraps the Elasticsearch TypedClient with vector database functionality

func NewClient

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

NewClient creates a new Elasticsearch client

func (*Client) Close

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

Close closes the Elasticsearch client connection

func (*Client) Health

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

Health checks the health of the Elasticsearch cluster

type Config

type Config struct {
	// Connection settings (choose one method)
	// Method 1: Elastic Cloud
	CloudID string // Cloud ID from Elastic Cloud console
	APIKey  string // API key for authentication

	// Method 2: Self-hosted
	Addresses []string // List of Elasticsearch addresses (e.g., ["https://localhost:9200"])

	// Authentication (for self-hosted)
	Username string
	Password string

	// Optional settings
	CertFingerprint string // SHA256 fingerprint for cert validation
	Timeout         int    // Timeout in seconds (default: 10)
	MaxRetries      int    // Max retry attempts (default: 3)
	EnableDebugLog  bool   // Enable detailed logging

	// Vector search settings
	VectorDimensions int    // Embedding vector dimensions (e.g., 1536 for OpenAI)
	SimilarityMetric string // Similarity: "cosine", "dot_product", "l2_norm"
}

Config holds Elasticsearch client configuration

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets default values for optional fields

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type Factory

type Factory struct{}

Factory implements the ClientFactory interface for Elasticsearch

func NewFactory

func NewFactory() *Factory

NewFactory creates a new Elasticsearch factory

func (*Factory) CreateClient

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

CreateClient creates a new Elasticsearch 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 Elasticsearch

Jump to

Keyboard shortcuts

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