redis

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 17 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 Redis Client to implement vectordb.VectorDBClient.

func NewAdapter

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

NewAdapter creates a new Redis adapter from vectordb.Config. Derives auth, TLS, and address from the URL when explicit fields are empty.

func (*Adapter) CollectionExists

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

CollectionExists checks if a collection exists.

func (*Adapter) CreateCollection

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

CreateCollection creates a new collection.

func (*Adapter) CreateDocument

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

CreateDocument creates a single document, auto-generating embeddings if needed.

func (*Adapter) CreateDocuments

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

CreateDocuments creates multiple documents in batch.

func (*Adapter) DeleteCollection

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

DeleteCollection deletes a collection.

func (*Adapter) DeleteDocument

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

DeleteDocument deletes a single 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. Returns an error if metadata is nil or empty to prevent accidental full-collection deletes.

func (*Adapter) GetCollectionCount

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

GetCollectionCount returns the document count for a collection.

func (*Adapter) GetDefaultSchema

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

GetDefaultSchema returns a default schema.

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 returns the schema for a collection.

func (*Adapter) ListCollections

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

ListCollections returns all collections.

func (*Adapter) ListDocuments

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

ListDocuments returns documents with pagination.

func (*Adapter) SearchBM25

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

SearchBM25 performs keyword-based search using Redis full-text search.

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 is not yet implemented for Redis. TODO: implement fusion of KNN + full-text in a single FT.SEARCH query.

func (*Adapter) SearchSemantic

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

SearchSemantic performs vector similarity search.

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 is not supported — Redis indexes are immutable.

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 a go-redis client with vector-search helpers.

func NewClient

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

NewClient creates a new Redis client. Applies defaults to a copy of cfg so the caller's struct is not mutated.

func (*Client) Close

func (c *Client) Close() error

Close closes the Redis connection.

func (*Client) CollectionExists

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

CollectionExists checks if a RediSearch index exists for the collection.

func (*Client) CreateCollection

func (c *Client) CreateCollection(ctx context.Context, name string, dims int, metric string) error

CreateCollection creates a RediSearch index that acts as a collection.

func (*Client) CreateDocument

func (c *Client) CreateDocument(ctx context.Context, collection string, doc *vectordb.Document) error

CreateDocument stores a single document as a Redis HASH.

func (*Client) CreateDocuments

func (c *Client) CreateDocuments(ctx context.Context, collection string, docs []*vectordb.Document) error

CreateDocuments stores multiple documents using a pipeline.

func (*Client) DeleteCollection

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

DeleteCollection drops the RediSearch index and all associated documents.

func (*Client) DeleteDocument

func (c *Client) DeleteDocument(ctx context.Context, collection, docID string) error

DeleteDocument deletes a single document.

func (*Client) DeleteDocuments

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

DeleteDocuments deletes multiple documents.

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, collection, docID string) (*vectordb.Document, error)

GetDocument retrieves a document by ID.

func (*Client) Health

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

Health checks if the Redis server is reachable and has the search module.

func (*Client) ListCollections

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

ListCollections returns all weave-managed RediSearch indexes.

func (*Client) ListDocuments

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

ListDocuments returns documents using FT.SEARCH with wildcard.

func (*Client) SearchByMetadata

func (c *Client) SearchByMetadata(ctx context.Context, collection string, metadata map[string]interface{}, limit int) ([]SearchResult, error)

SearchByMetadata searches documents by metadata field values.

func (*Client) SearchFullText

func (c *Client) SearchFullText(ctx context.Context, collection, query string, limit int) ([]SearchResult, error)

SearchFullText performs full-text search on the content field.

func (*Client) SearchSemantic

func (c *Client) SearchSemantic(ctx context.Context, collection string, vector []float32, topK int) ([]SearchResult, error)

SearchSemantic performs KNN vector search via FT.SEARCH.

func (*Client) UpdateDocument

func (c *Client) UpdateDocument(ctx context.Context, collection string, doc *vectordb.Document) error

UpdateDocument updates (upserts) a document.

type Config

type Config struct {
	Addr             string // host:port (e.g. "localhost:6379")
	Password         string
	Username         string
	UseTLS           bool
	DB               int    // Redis database number
	VectorDimensions int    // e.g. 1536
	SimilarityMetric string // COSINE, L2, IP
	Timeout          int    // seconds
}

Config holds Redis client configuration.

type Factory

type Factory struct{}

Factory implements the ClientFactory interface for Redis

func NewFactory

func NewFactory() *Factory

NewFactory creates a new Redis factory

func (*Factory) CreateClient

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

CreateClient creates a new Redis vector database 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 Redis

type SearchResult

type SearchResult struct {
	Document *vectordb.Document
	Score    float64
}

SearchResult holds a document and its search score.

Jump to

Keyboard shortcuts

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