mongodb

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 11 Imported by: 2 modules, 2 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

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

func NewAdapter

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

NewAdapter creates a new MongoDB adapter from the vectordb.Config

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) SearchSemantic

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

SearchSemantic performs semantic search using MongoDB Atlas Vector Search

type Client

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

Client wraps the MongoDB client with vector database functionality

func NewClient

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

NewClient creates a new MongoDB Atlas Vector Search client

func (*Client) Close

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

Close closes the MongoDB 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 collection with Atlas Vector Search index

func (*Client) DeleteAllDocuments

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

DeleteAllDocuments deletes all documents in a collection

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) GetDefaultSchema

func (c *Client) GetDefaultSchema(schemaType vectordb.SchemaType, collectionName string) *vectordb.CollectionSchema

GetDefaultSchema returns a default schema for the given type

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, collectionName string) (*vectordb.CollectionSchema, error)

GetSchema retrieves the schema for a collection Note: MongoDB is schema-less, so we return a default schema

func (*Client) Health

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

Health checks the health of the MongoDB 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 int, offset int) ([]*vectordb.Document, error)

ListDocuments returns a list of documents in 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 MongoDB text search

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

func (*Client) SearchHybrid

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

SearchHybrid performs hybrid search combining vector and keyword search

func (*Client) UpdateDocument

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

UpdateDocument updates an existing document

func (*Client) UpdateSchema

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

UpdateSchema updates the schema for a collection Note: MongoDB is schema-less, so this is a no-op

func (*Client) ValidateSchema

func (c *Client) ValidateSchema(schema *vectordb.CollectionSchema) error

ValidateSchema validates a schema definition

type Config

type Config struct {
	// Connection settings
	URI      string // MongoDB connection URI (mongodb+srv://...)
	Database string // Database name
	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: "cosine", "euclidean", or "dotProduct"
}

Config holds MongoDB client configuration

type Factory

type Factory struct{}

Factory implements the ClientFactory interface for MongoDB

func NewFactory

func NewFactory() *Factory

NewFactory creates a new MongoDB factory

func (*Factory) CreateClient

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

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

Jump to

Keyboard shortcuts

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