Documentation
¶
Index ¶
- Constants
- Variables
- func CountFacts(seq iter.Seq2[Fact, error]) (int, error)
- func Filter(seq iter.Seq2[Fact, error], pred func(Fact) bool) iter.Seq2[Fact, error]
- func Map[T any](seq iter.Seq2[Fact, error], fn func(Fact) (T, error)) iter.Seq2[T, error]
- func MustValue[T any](f Fact) T
- func ShouldPruneTriple(value []byte, wantEntityType uint16, wantPublic bool) bool
- func Value[T any](f Fact) (T, bool)
- func ValueOrDefault[T any](f Fact, defaultVal T) T
- type Builder
- func (b *Builder) CandidateMultiplier(multiplier int) *Builder
- func (b *Builder) Execute(ctx context.Context) ([]Result, error)
- func (b *Builder) FilterFirst() *Builder
- func (b *Builder) InTopic(topicID uint32) *Builder
- func (b *Builder) JoinWithLFTJ(relations []query.RelationPattern, resultVars []string) *Builder
- func (b *Builder) Limit(n int) *Builder
- func (b *Builder) SimilarTo(vec []float32) *Builder
- func (b *Builder) SimilarToWithThreshold(vec []float32, threshold float32) *Builder
- func (b *Builder) Where(predicate string, object interface{}) *Builder
- type Fact
- type FilterOpt
- type MEBStore
- func (m *MEBStore) Add(atom ast.Atom) bool
- func (m *MEBStore) AddDocument(docKey string, content []byte, vec []float32, metadata map[string]any) error
- func (m *MEBStore) AddDocumentWithTopic(topicID uint32, docKey string, content []byte, vec []float32, ...) error
- func (m *MEBStore) AddFact(fact Fact) error
- func (m *MEBStore) AddFactBatch(facts []Fact) error
- func (m *MEBStore) CircuitBreaker() *circuit.Breaker
- func (m *MEBStore) CircuitBreakerMetrics() circuit.Metrics
- func (m *MEBStore) CircuitBreakerMetricsSnapshot() circuit.MetricsSnapshot
- func (m *MEBStore) Close() error
- func (m *MEBStore) Contains(atom ast.Atom) bool
- func (m *MEBStore) Count() uint64
- func (m *MEBStore) DeleteDocument(docKey string) error
- func (m *MEBStore) DeleteDocumentWithTopic(docKey string, topicID uint32) error
- func (m *MEBStore) DeleteFactsBySubject(subject string) error
- func (m *MEBStore) Dict() dict.Dictionary
- func (st *MEBStore) EnableHNSW(cfg *vector.HNSWConfig) error
- func (st *MEBStore) EnableIVFPQ(cfg *vector.IVFPQConfig) error
- func (m *MEBStore) Exists(s, p, o string) bool
- func (m *MEBStore) Find() *Builder
- func (m *MEBStore) FindSubjectsByObject(ctx context.Context, predicate, object string) iter.Seq[string]
- func (m *MEBStore) GetContent(id uint64) ([]byte, error)
- func (m *MEBStore) GetContentByKey(docKey string) ([]byte, error)
- func (m *MEBStore) GetDocumentMetadata(docKey string) (map[string]any, error)
- func (m *MEBStore) GetFacts(atom ast.Atom, callback func(ast.Atom) error) error
- func (m *MEBStore) HasDocument(docKey string) (bool, error)
- func (st *MEBStore) IVFPQIndex() *vector.IVFPQIndex
- func (m *MEBStore) LFTJEngine() *query.LFTJEngine
- func (m *MEBStore) ListPredicates() []ast.PredicateSym
- func (m *MEBStore) LookupID(key string) (uint64, bool)
- func (m *MEBStore) Merge(other factstore.ReadOnlyFactStore) error
- func (m *MEBStore) MergeBatch(other factstore.ReadOnlyFactStore, batchSize int) error
- func (m *MEBStore) RecalculateStats() (uint64, error)
- func (m *MEBStore) RegisterTelemetrySink(sink TelemetrySink)
- func (m *MEBStore) Reset() error
- func (m *MEBStore) ResolveID(id uint64) (string, error)
- func (m *MEBStore) RunValueLogGC(ratio float64) error
- func (m *MEBStore) Scan(s, p, o string) iter.Seq2[Fact, error]
- func (m *MEBStore) ScanContext(ctx context.Context, s, p, o string) iter.Seq2[Fact, error]
- func (m *MEBStore) ScanInTopic(topicID uint32, s, p, o string) iter.Seq2[Fact, error]
- func (m *MEBStore) ScanInTopicContext(ctx context.Context, topicID uint32, s, p, o string) iter.Seq2[Fact, error]
- func (m *MEBStore) ScanSubjects(ctx context.Context) iter.Seq[string]
- func (m *MEBStore) ScanSubjectsByPrefix(ctx context.Context, prefix string) iter.Seq[string]
- func (m *MEBStore) ScanWithFilters(s, p, o string, filters []PredicateFilter) iter.Seq2[Fact, error]
- func (m *MEBStore) ScanWithFiltersContext(ctx context.Context, s, p, o string, filters []PredicateFilter) iter.Seq2[Fact, error]
- func (m *MEBStore) ScanWithPruning(ctx context.Context, s, p, o string, entityType uint16, wantPublic bool) iter.Seq2[Fact, error]
- func (m *MEBStore) SetCircuitBreakerConfig(config *circuit.Config)
- func (m *MEBStore) SetContent(id uint64, data []byte) error
- func (m *MEBStore) SetDefaultEntityType(entityType uint16)
- func (m *MEBStore) SetDefaultFlags(flags uint16)
- func (m *MEBStore) SetRetention(maxFacts uint64) error
- func (m *MEBStore) SetTopicID(topicID uint32)
- func (m *MEBStore) TopicID() uint32
- func (st *MEBStore) TrainIVFPQ(topicID uint32) error
- func (m *MEBStore) UnregisterTelemetrySink(sink TelemetrySink)
- func (m *MEBStore) Update(fn func(*StoreTxn) error) error
- func (m *MEBStore) Vectors() *vector.VectorRegistry
- func (m *MEBStore) View(fn func(*StoreTxn) error) error
- type NumericRange
- type PredicateFilter
- type PredicateFilterType
- type QueryFilter
- type Result
- type Results
- type Store
- type StoreTxn
- func (t *StoreTxn) AddFact(fact Fact) error
- func (t *StoreTxn) AddFactBatch(facts []Fact) error
- func (t *StoreTxn) AddFactBatchWithTopic(facts []Fact, topicID uint32) error
- func (t *StoreTxn) AddHNSWVector(topicID uint32, localID uint64, fullVec []float32) error
- func (t *StoreTxn) AddIVFVector(topicID uint32, localID uint64, fullVec []float32) error
- func (t *StoreTxn) AddVector(id uint64, vec []float32) error
- func (t *StoreTxn) AddVectorWithHash(id uint64, vec []float32, semanticHash uint8) error
- func (t *StoreTxn) BadgerTxn() *badger.Txn
- func (t *StoreTxn) DeleteDocument(docKey string) error
- func (t *StoreTxn) DeleteDocumentWithTopic(docKey string, topicID uint32) error
- func (t *StoreTxn) DeleteFactsBySubject(subject string) error
- func (t *StoreTxn) DeleteVector(id uint64) bool
- func (t *StoreTxn) Exists(s, p, o string) bool
- func (t *StoreTxn) GetContent(id uint64) ([]byte, error)
- func (t *StoreTxn) GetID(s string) (uint64, error)
- func (t *StoreTxn) GetOrCreateID(s string) (uint64, error)
- func (t *StoreTxn) GetString(id uint64) (string, error)
- func (t *StoreTxn) HasVector(id uint64) bool
- func (t *StoreTxn) Scan(ctx context.Context, s, p, o string) iterSeq2FactError
- func (t *StoreTxn) ScanInTopic(ctx context.Context, topicID uint32, s, p, o string) iterSeq2FactError
- func (t *StoreTxn) SearchHNSW(ctx context.Context, topicID uint32, queryVec []float32, k int) ([]Result, error)
- func (t *StoreTxn) SearchHybrid(ctx context.Context, queryVec []float32, k int) ([]Result, error)
- func (t *StoreTxn) SearchHybridWithFilters(ctx context.Context, queryVec []float32, k int, filters []FilterOpt) ([]Result, error)
- func (t *StoreTxn) SearchIVFPQ(ctx context.Context, topicID uint32, queryVec []float32, k int) ([]Result, error)
- func (t *StoreTxn) SetContent(id uint64, data []byte) error
- type TelemetryEvent
- type TelemetrySink
- type WAL
Constants ¶
const (
DefaultCandidateMultiplier = 10
)
Variables ¶
var ( // ErrInvalidFact is returned when a Fact has missing required fields // (empty Subject or Predicate) or an Object of an unsupported type. ErrInvalidFact = fmt.Errorf("invalid fact") // ErrStoreReadOnly is returned when a write operation is attempted on a // store opened with Config.ReadOnly = true. ErrStoreReadOnly = fmt.Errorf("store is read-only") // ErrInvalidQuery is returned when a query is malformed (e.g. empty // predicate in a context that requires one). ErrInvalidQuery = fmt.Errorf("invalid query") // ErrFactNotFound is returned by lookup helpers when no matching fact // is found. ErrFactNotFound = fmt.Errorf("fact not found") // ErrEmptyBatch is returned when a batch write is called with no facts. ErrEmptyBatch = fmt.Errorf("empty batch") // ErrWALClosed is returned by WAL.Append or WAL.Clear when the WAL has // been closed or is mid-clear. Callers should treat this as a hard // failure rather than a silent drop. ErrWALClosed = fmt.Errorf("WAL is closed") // ErrUnknownTriplePrefix is returned by key encoders when an unknown // prefix byte is passed. Surfaces bugs that would otherwise be silently // mis-encoded as SPO. ErrUnknownTriplePrefix = fmt.Errorf("unknown triple key prefix") )
Functions ¶
func ShouldPruneTriple ¶
ShouldPruneTriple reads semantic hints from a 16-byte triple value and returns true if the triple should be pruned based on the requested entity type and public flag.
func ValueOrDefault ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func (*Builder) CandidateMultiplier ¶
func (*Builder) Execute ¶
Execute runs the query using RBO to automatically select the optimal strategy. FilterFirst() is kept as an explicit override for manual control.
func (*Builder) FilterFirst ¶
FilterFirst enables candidate-set pre-filtering for this query. When enabled, filters are evaluated against the graph index FIRST, building a set of matching subject IDs. Vector search results that aren't in this set are then skipped in the result loop (post-filter).
Important: This is NOT true predicate pushdown — vector search still scans all vectors and computes similarities for all candidates. The benefit comes from skipping dictionary lookups and content fetches for non-matching vectors. Most effective when:
- Filters are highly selective (< 10% match rate)
- Content fetch or dict lookup is expensive relative to vector search
func (*Builder) InTopic ¶
InTopic restricts the search to a specific topic. The TopicID is used for topic-aware vector search and scan operations.
func (*Builder) JoinWithLFTJ ¶
func (b *Builder) JoinWithLFTJ(relations []query.RelationPattern, resultVars []string) *Builder
JoinWithLFTJ adds LFTJ relations for structural expansion after vector search. The seedVar must match a variable name used in the relations. Results are streamed — no intermediate materialization.
func (*Builder) SimilarToWithThreshold ¶
type FilterOpt ¶
type FilterOpt struct {
Predicate string
Object interface{}
}
FilterOpt is a filter option for hybrid search.
type MEBStore ¶
type MEBStore struct {
// contains filtered or unexported fields
}
func (*MEBStore) AddDocument ¶
func (*MEBStore) AddDocumentWithTopic ¶
func (*MEBStore) AddFactBatch ¶
func (*MEBStore) CircuitBreaker ¶
func (*MEBStore) CircuitBreakerMetrics ¶
func (*MEBStore) CircuitBreakerMetricsSnapshot ¶
func (m *MEBStore) CircuitBreakerMetricsSnapshot() circuit.MetricsSnapshot
func (*MEBStore) DeleteDocument ¶
func (*MEBStore) DeleteDocumentWithTopic ¶
func (*MEBStore) DeleteFactsBySubject ¶
func (*MEBStore) Dict ¶
func (m *MEBStore) Dict() dict.Dictionary
func (*MEBStore) EnableHNSW ¶
func (st *MEBStore) EnableHNSW(cfg *vector.HNSWConfig) error
func (*MEBStore) EnableIVFPQ ¶
func (st *MEBStore) EnableIVFPQ(cfg *vector.IVFPQConfig) error
func (*MEBStore) Exists ¶
Exists performs an efficient key-only existence check without decoding strings.
func (*MEBStore) FindSubjectsByObject ¶
func (m *MEBStore) FindSubjectsByObject(ctx context.Context, predicate, object string) iter.Seq[string]
FindSubjectsByObject returns all subjects matching exact predicate and object. Uses SPO index scan across ALL topics - does not filter by current topicID. Returns empty iterator if no matches found (never returns error for "not found").
func (*MEBStore) GetContentByKey ¶
func (*MEBStore) GetDocumentMetadata ¶
func (*MEBStore) IVFPQIndex ¶
func (st *MEBStore) IVFPQIndex() *vector.IVFPQIndex
func (*MEBStore) LFTJEngine ¶
func (m *MEBStore) LFTJEngine() *query.LFTJEngine
func (*MEBStore) ListPredicates ¶
func (m *MEBStore) ListPredicates() []ast.PredicateSym
func (*MEBStore) MergeBatch ¶
func (m *MEBStore) MergeBatch(other factstore.ReadOnlyFactStore, batchSize int) error
MergeBatch imports facts from another store in batches, avoiding the O(N²) per-fact Exists() check. Existing facts are silently skipped.
func (*MEBStore) RecalculateStats ¶
func (*MEBStore) RegisterTelemetrySink ¶
func (m *MEBStore) RegisterTelemetrySink(sink TelemetrySink)
func (*MEBStore) RunValueLogGC ¶
func (*MEBStore) ScanContext ¶
func (*MEBStore) ScanInTopic ¶
ScanInTopic scans facts within a specific topic. The TopicID is packed into the ID structure for data locality. This enables scanning only the prefix range belonging to the requested topic.
func (*MEBStore) ScanInTopicContext ¶
func (m *MEBStore) ScanInTopicContext(ctx context.Context, topicID uint32, s, p, o string) iter.Seq2[Fact, error]
ScanInTopicContext scans facts within a specific topic with context.
func (*MEBStore) ScanSubjects ¶
ScanSubjectsByPrefix returns all subjects starting with the given prefix string. Uses SPO index with LSM-tree prefix scan - O(log N + k) where k is number of results. The prefix is matched against the full subject string (e.g., "project/pkg/" matches all subjects under that path like "project/pkg/server/server.go:NewServer"). Returns empty iterator if no matches found (never returns error for "not found"). ScanSubjects returns all subjects in the store by scanning the SPO index. Warning: This performs a full table scan.
func (*MEBStore) ScanSubjectsByPrefix ¶
func (*MEBStore) ScanWithFilters ¶
func (*MEBStore) ScanWithFiltersContext ¶
func (*MEBStore) ScanWithPruning ¶
func (m *MEBStore) ScanWithPruning(ctx context.Context, s, p, o string, entityType uint16, wantPublic bool) iter.Seq2[Fact, error]
ScanWithPruning scans facts with semantic hints pruning. entityType: only yield triples matching this entity type (0 = no pruning). wantPublic: if true, only yield triples with IsPublic flag.
func (*MEBStore) SetCircuitBreakerConfig ¶
func (*MEBStore) SetDefaultEntityType ¶
SetDefaultEntityType sets the default entity type for semantic hints. Use keys.EntityFunc, EntityVar, EntityClass, etc.
func (*MEBStore) SetDefaultFlags ¶
SetDefaultFlags sets the default flags for semantic hints. Use keys.FlagIsPublic, FlagIsDeprecated, FlagIsTest, FlagIsGenerated.
func (*MEBStore) SetRetention ¶
func (*MEBStore) SetTopicID ¶
SetTopicID sets the 24-bit topic ID for symmetric bit-packing. All facts added after this call will use the new topic ID. Supports up to 16M isolated namespaces (topics). Panics if topicID is 0 (reserved as invalid).
func (*MEBStore) TrainIVFPQ ¶
func (*MEBStore) UnregisterTelemetrySink ¶
func (m *MEBStore) UnregisterTelemetrySink(sink TelemetrySink)
func (*MEBStore) Update ¶
Update executes a read-write transaction with automatic commit/rollback. In-memory side effects (counters, mmap caches, dict caches) are applied only after the Badger transaction commits successfully, using accumulated deltas. BadgerDB SyncWrites: true ensures durability for the transaction path.
func (*MEBStore) Vectors ¶
func (m *MEBStore) Vectors() *vector.VectorRegistry
type NumericRange ¶
NumericRange represents a closed [Min, Max] numeric range for PredicateRange filters.
type PredicateFilter ¶
type PredicateFilter struct {
Type PredicateFilterType
Value interface{} // string for regex/contains; float64 for gt/lt/gte/lte; NumericRange for range
// contains filtered or unexported fields
}
func MustPredicateFilter ¶
func MustPredicateFilter(filterType PredicateFilterType, value interface{}) *PredicateFilter
MustPredicateFilter creates a PredicateFilter, panicking on invalid input.
func NewPredicateFilter ¶
func NewPredicateFilter(filterType PredicateFilterType, value interface{}) (*PredicateFilter, error)
NewPredicateFilter creates a PredicateFilter, pre-compiling regex patterns.
type PredicateFilterType ¶
type PredicateFilterType string
const ( PredicateRegex PredicateFilterType = "regex" PredicateRange PredicateFilterType = "range" PredicateGT PredicateFilterType = "gt" PredicateLT PredicateFilterType = "lt" PredicateGTE PredicateFilterType = "gte" PredicateLTE PredicateFilterType = "lte" PredicateContains PredicateFilterType = "contains" )
type QueryFilter ¶
type QueryFilter struct {
Predicate string
Object interface{}
}
type Result ¶
type Result struct {
ID uint64 // Internal dictionary ID
Key string // Human-readable key (decoded from dictionary)
Score float32 // Similarity score (0-1, higher is better)
Content string // Document content (empty if not found)
}
Result represents a single neuro-symbolic search result.
type StoreTxn ¶
type StoreTxn struct {
// contains filtered or unexported fields
}
StoreTxn wraps a BadgerDB transaction with store-specific helpers. Created via MEBStore.View() or MEBStore.Update().
func (*StoreTxn) AddFactBatch ¶
AddFactBatch adds multiple facts within the transaction. Uses the store's current topicID. Durability is provided by BadgerDB SyncWrites: true (no WAL needed for txn path).
func (*StoreTxn) AddFactBatchWithTopic ¶
AddFactBatchWithTopic adds multiple facts within the transaction using a specific topicID. Durability is provided by BadgerDB SyncWrites: true (no WAL needed for txn path).
func (*StoreTxn) AddHNSWVector ¶
AddHNSWVector adds a vector to the HNSW index.
func (*StoreTxn) AddIVFVector ¶
AddIVFVector adds a vector to the IVF-PQ index.
func (*StoreTxn) AddVector ¶
AddVector adds a vector within the transaction. The Badger write is done in-txn; the mmap cache update is deferred to post-commit.
func (*StoreTxn) AddVectorWithHash ¶
AddVectorWithHash adds a vector with a semantic hash within the transaction.
func (*StoreTxn) DeleteDocument ¶
DeleteDocument atomically deletes a document (content, vector, facts, dict entry) within the transaction. Uses the store's current topicID. In-memory vector/dict mutations are deferred to post-commit.
func (*StoreTxn) DeleteDocumentWithTopic ¶
DeleteDocumentWithTopic atomically deletes a document using a specific topicID.
func (*StoreTxn) DeleteFactsBySubject ¶
DeleteFactsBySubject deletes all facts for the given subject within the transaction.
func (*StoreTxn) DeleteVector ¶
DeleteVector deletes a vector within the transaction. In-memory registry mutation is deferred to post-commit.
func (*StoreTxn) GetContent ¶
GetContent retrieves content by ID within the transaction.
func (*StoreTxn) GetOrCreateID ¶
GetOrCreateID gets or creates a dictionary ID for the given string within the transaction.
func (*StoreTxn) GetString ¶
GetString resolves a dictionary ID to its string within the transaction.
func (*StoreTxn) Scan ¶
Scan iterates over facts matching the given subject, predicate, object. Uses the store's current topicID.
func (*StoreTxn) ScanInTopic ¶
func (t *StoreTxn) ScanInTopic(ctx context.Context, topicID uint32, s, p, o string) iterSeq2FactError
ScanInTopic iterates over facts matching the given subject, predicate, object within the specified topic.
func (*StoreTxn) SearchHNSW ¶
func (t *StoreTxn) SearchHNSW(ctx context.Context, topicID uint32, queryVec []float32, k int) ([]Result, error)
SearchHNSW searches the HNSW index directly (bypassing RBO).
func (*StoreTxn) SearchHybrid ¶
SearchHybrid uses the RBO to select the optimal search strategy.
func (*StoreTxn) SearchHybridWithFilters ¶
func (t *StoreTxn) SearchHybridWithFilters(ctx context.Context, queryVec []float32, k int, filters []FilterOpt) ([]Result, error)
SearchHybridWithFilters is like SearchHybrid but accepts optional FilterOpt filters.
type TelemetryEvent ¶
type TelemetrySink ¶
type TelemetrySink interface {
OnEvent(event TelemetryEvent)
}
type WAL ¶
type WAL struct {
// contains filtered or unexported fields
}
func NewWAL ¶
NewWAL opens or creates a v2 WAL file. Returns an error if an existing WAL file has an unsupported format (e.g. v1) — the caller should delete the file.
func (*WAL) Append ¶
Append writes a single entry to the WAL with CRC32C. Returns nil if no WAL is configured (in-memory mode). Returns ErrWALClosed if the WAL has been closed or is currently being cleared, rather than silently dropping the entry.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
bench
|
|
|
datasets
Package datasets provides embedded test datasets for MEB benchmarks.
|
Package datasets provides embedded test datasets for MEB benchmarks. |
|
cmd
|
|
|
bench
command
Command bench runs the MEB benchmark suite and outputs a JSON report.
|
Command bench runs the MEB benchmark suite and outputs a JSON report. |
|
Package vector provides ANN index implementations.
|
Package vector provides ANN index implementations. |