Documentation
¶
Overview ¶
Package memory provides in-memory implementations for testing and development.
Index ¶
- type Collection
- type Document
- type HashEmbedder
- type KnowledgeGraph
- func (kg *KnowledgeGraph) AddEdge(ctx context.Context, edge graph.Edge) error
- func (kg *KnowledgeGraph) AddEdgeBatch(ctx context.Context, edges []graph.Edge) error
- func (kg *KnowledgeGraph) AddNode(ctx context.Context, node graph.Node) error
- func (kg *KnowledgeGraph) AddNodeBatch(ctx context.Context, nodes []graph.Node) error
- func (kg *KnowledgeGraph) DeleteEdge(ctx context.Context, from, to, edgeType string) error
- func (kg *KnowledgeGraph) DeleteNode(ctx context.Context, id string) error
- func (kg *KnowledgeGraph) DeleteNodeBatch(ctx context.Context, ids []string) error
- func (kg *KnowledgeGraph) EdgeCount() int
- func (kg *KnowledgeGraph) FindNodes(ctx context.Context, nodeType string, filters map[string]string) ([]graph.Node, error)
- func (kg *KnowledgeGraph) Name() string
- func (kg *KnowledgeGraph) NodeCount() int
- func (kg *KnowledgeGraph) Traverse(ctx context.Context, startNodes []string, opts graph.TraversalOptions) (*graph.TraversalResult, error)
- func (kg *KnowledgeGraph) UpsertEdge(ctx context.Context, edge graph.Edge) error
- func (kg *KnowledgeGraph) UpsertEdgeBatch(ctx context.Context, edges []graph.Edge) error
- func (kg *KnowledgeGraph) UpsertNode(ctx context.Context, node graph.Node) error
- func (kg *KnowledgeGraph) UpsertNodeBatch(ctx context.Context, nodes []graph.Node) error
- type Manager
- func (m *Manager) Count(ctx context.Context, collectionName string) (int, error)
- func (m *Manager) CreateCollection(ctx context.Context, name, description string) (*Collection, error)
- func (m *Manager) Delete(ctx context.Context, collectionName, key string) error
- func (m *Manager) DeleteCollection(ctx context.Context, name string) error
- func (m *Manager) Get(ctx context.Context, collectionName, key string) (*Document, error)
- func (m *Manager) GetCollection(name string) (*Collection, error)
- func (m *Manager) GetOrCreateCollection(ctx context.Context, name, description string) (*Collection, error)
- func (m *Manager) List(ctx context.Context, collectionName string, limit, offset int) ([]Document, error)
- func (m *Manager) ListCollections() []string
- func (m *Manager) Search(ctx context.Context, collectionName, query string, opts SearchOptions) ([]SearchResult, error)
- func (m *Manager) Store(ctx context.Context, collectionName, key string, doc *Document) error
- type ManagerConfig
- type SearchOptions
- type SearchResult
- type VectorIndex
- func (idx *VectorIndex) Count() int
- func (idx *VectorIndex) Delete(ctx context.Context, id string) error
- func (idx *VectorIndex) DeleteBatch(ctx context.Context, ids []string) error
- func (idx *VectorIndex) Insert(ctx context.Context, node vector.Node) error
- func (idx *VectorIndex) InsertBatch(ctx context.Context, nodes []vector.Node) error
- func (idx *VectorIndex) Name() string
- func (idx *VectorIndex) Search(ctx context.Context, embedding []float32, k int, filters map[string]string) ([]vector.SearchResult, error)
- func (idx *VectorIndex) Upsert(ctx context.Context, node vector.Node) error
- func (idx *VectorIndex) UpsertBatch(ctx context.Context, nodes []vector.Node) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶ added in v0.3.0
type Collection struct {
// Name is the collection name.
Name string
// Description is an optional description.
Description string
// VectorIndex holds the vector embeddings.
VectorIndex vector.Index
// contains filtered or unexported fields
}
Collection represents a named collection of documents.
type Document ¶ added in v0.3.0
type Document struct {
// ID is the unique document identifier.
ID string
// Content is the document text.
Content string
// Embedding is the vector embedding (optional, computed if nil).
Embedding []float32
// Metadata contains additional document metadata.
Metadata map[string]string
// CreatedAt is when the document was created.
CreatedAt time.Time
// UpdatedAt is when the document was last updated.
UpdatedAt time.Time
}
Document represents a document to store in memory.
type HashEmbedder ¶
type HashEmbedder struct {
// contains filtered or unexported fields
}
HashEmbedder creates deterministic embeddings using hashing. This is for testing only - not suitable for production.
func NewHashEmbedder ¶
func NewHashEmbedder(dimensions int) *HashEmbedder
NewHashEmbedder creates a new hash-based embedder.
func (*HashEmbedder) EmbedBatch ¶
EmbedBatch implements vector.Embedder.
func (*HashEmbedder) Model ¶
func (e *HashEmbedder) Model() string
Model implements vector.Embedder.
type KnowledgeGraph ¶
type KnowledgeGraph struct {
// contains filtered or unexported fields
}
KnowledgeGraph is an in-memory knowledge graph.
func NewKnowledgeGraph ¶
func NewKnowledgeGraph(name string) *KnowledgeGraph
NewKnowledgeGraph creates a new in-memory knowledge graph.
func (*KnowledgeGraph) AddEdgeBatch ¶
AddEdgeBatch implements graph.BatchKnowledgeGraph.
func (*KnowledgeGraph) AddNodeBatch ¶
AddNodeBatch implements graph.BatchKnowledgeGraph.
func (*KnowledgeGraph) DeleteEdge ¶
func (kg *KnowledgeGraph) DeleteEdge(ctx context.Context, from, to, edgeType string) error
DeleteEdge implements graph.KnowledgeGraph.
func (*KnowledgeGraph) DeleteNode ¶
func (kg *KnowledgeGraph) DeleteNode(ctx context.Context, id string) error
DeleteNode implements graph.KnowledgeGraph.
func (*KnowledgeGraph) DeleteNodeBatch ¶
func (kg *KnowledgeGraph) DeleteNodeBatch(ctx context.Context, ids []string) error
DeleteNodeBatch implements graph.BatchKnowledgeGraph.
func (*KnowledgeGraph) EdgeCount ¶
func (kg *KnowledgeGraph) EdgeCount() int
EdgeCount returns the number of edges in the graph.
func (*KnowledgeGraph) FindNodes ¶
func (kg *KnowledgeGraph) FindNodes(ctx context.Context, nodeType string, filters map[string]string) ([]graph.Node, error)
FindNodes implements graph.KnowledgeGraph.
func (*KnowledgeGraph) Name ¶
func (kg *KnowledgeGraph) Name() string
Name implements graph.KnowledgeGraph.
func (*KnowledgeGraph) NodeCount ¶
func (kg *KnowledgeGraph) NodeCount() int
NodeCount returns the number of nodes in the graph.
func (*KnowledgeGraph) Traverse ¶
func (kg *KnowledgeGraph) Traverse(ctx context.Context, startNodes []string, opts graph.TraversalOptions) (*graph.TraversalResult, error)
Traverse implements graph.KnowledgeGraph.
func (*KnowledgeGraph) UpsertEdge ¶
UpsertEdge implements graph.KnowledgeGraph.
func (*KnowledgeGraph) UpsertEdgeBatch ¶
UpsertEdgeBatch implements graph.BatchKnowledgeGraph.
func (*KnowledgeGraph) UpsertNode ¶
UpsertNode implements graph.KnowledgeGraph.
func (*KnowledgeGraph) UpsertNodeBatch ¶
UpsertNodeBatch implements graph.BatchKnowledgeGraph.
type Manager ¶ added in v0.3.0
type Manager struct {
// contains filtered or unexported fields
}
Manager manages named collections of documents.
func NewManager ¶ added in v0.3.0
func NewManager(cfg ManagerConfig) *Manager
NewManager creates a new memory manager.
func (*Manager) CreateCollection ¶ added in v0.3.0
func (m *Manager) CreateCollection(ctx context.Context, name, description string) (*Collection, error)
CreateCollection creates a new named collection.
func (*Manager) DeleteCollection ¶ added in v0.3.0
DeleteCollection removes a collection.
func (*Manager) GetCollection ¶ added in v0.3.0
func (m *Manager) GetCollection(name string) (*Collection, error)
GetCollection retrieves a collection by name.
func (*Manager) GetOrCreateCollection ¶ added in v0.3.0
func (m *Manager) GetOrCreateCollection(ctx context.Context, name, description string) (*Collection, error)
GetOrCreateCollection gets an existing collection or creates a new one.
func (*Manager) List ¶ added in v0.3.0
func (m *Manager) List(ctx context.Context, collectionName string, limit, offset int) ([]Document, error)
List returns all documents in a collection.
func (*Manager) ListCollections ¶ added in v0.3.0
ListCollections returns all collection names.
func (*Manager) Search ¶ added in v0.3.0
func (m *Manager) Search(ctx context.Context, collectionName, query string, opts SearchOptions) ([]SearchResult, error)
Search performs a similarity search in a collection.
type ManagerConfig ¶ added in v0.3.0
ManagerConfig configures the memory manager.
type SearchOptions ¶ added in v0.3.0
type SearchOptions struct {
// TopK is the maximum number of results.
TopK int
// MinScore filters results below this threshold.
MinScore float64
// Filters are metadata filters to apply.
Filters map[string]string
// IncludeMetadata includes metadata in results.
IncludeMetadata bool
}
SearchOptions configures a search operation.
type SearchResult ¶ added in v0.3.0
type SearchResult struct {
// Document is the matched document.
Document Document
// Score is the similarity score.
Score float64
}
SearchResult represents a search result.
type VectorIndex ¶
type VectorIndex struct {
// contains filtered or unexported fields
}
VectorIndex is an in-memory vector index using brute-force search.
func NewVectorIndex ¶
func NewVectorIndex(name string) *VectorIndex
NewVectorIndex creates a new in-memory vector index.
func (*VectorIndex) Count ¶
func (idx *VectorIndex) Count() int
Count returns the number of nodes in the index.
func (*VectorIndex) Delete ¶
func (idx *VectorIndex) Delete(ctx context.Context, id string) error
Delete implements vector.Index.
func (*VectorIndex) DeleteBatch ¶
func (idx *VectorIndex) DeleteBatch(ctx context.Context, ids []string) error
DeleteBatch implements vector.BatchIndex.
func (*VectorIndex) InsertBatch ¶
InsertBatch implements vector.BatchIndex.
func (*VectorIndex) Search ¶
func (idx *VectorIndex) Search(ctx context.Context, embedding []float32, k int, filters map[string]string) ([]vector.SearchResult, error)
Search implements vector.Index.
func (*VectorIndex) UpsertBatch ¶
UpsertBatch implements vector.BatchIndex.