Query API Reference
The Query API provides a flexible way to search for memories based on multiple criteria. This document provides a detailed reference for the query-related APIs in EngramDB.QueryBuilder
TheQueryBuilder class provides a fluent interface for building complex queries.
Creating a Query
QueryBuilder::new()
Creates a new query builder.
Returns:
- A new
QueryBuilderinstance
Query Criteria
with_vector(query_vector)
Sets the query vector for similarity search.
Parameters:
query_vector:Vec<f32>- The query vector
Self- The query builder for method chaining
with_similarity_threshold(threshold)
Sets the minimum similarity threshold for vector search.
Parameters:
threshold:f32- Minimum similarity threshold (0.0 to 1.0)
Self- The query builder for method chaining
with_attribute_filter(filter)
Adds an attribute filter to the query.
Parameters:
filter:AttributeFilter- The attribute filter to add
Self- The query builder for method chaining
with_temporal_filter(filter)
Adds a temporal filter to the query.
Parameters:
filter:TemporalFilter- The temporal filter to add
Self- The query builder for method chaining
with_limit(limit)
Sets the maximum number of results to return.
Parameters:
limit:usize- Maximum number of results
Self- The query builder for method chaining
with_exclude_ids(ids)
Adds IDs to exclude from the results.
Parameters:
ids:Vec<Uuid>- IDs to exclude
Self- The query builder for method chaining
Executing the Query
execute(vector_index, memory_nodes)
Executes the query against a vector index and a set of memory nodes.
Parameters:
vector_index:&VectorIndex- The vector index to searchmemory_nodes:F- A function that can retrieve memory nodes by ID
Result<Vec<MemoryNode>>- A vector of memory nodes matching the query, sorted by relevance
AttributeFilter
TheAttributeFilter class provides methods for filtering memories based on their attributes.
Creating Filters
AttributeFilter::equals(key, value)
Creates a filter that matches attributes equal to the specified value.
Parameters:
key:&str- The attribute keyvalue:AttributeValue- The value to compare against
- A new
AttributeFilterinstance
AttributeFilter::not_equals(key, value)
Creates a filter that matches attributes not equal to the specified value.
Parameters:
key:&str- The attribute keyvalue:AttributeValue- The value to compare against
- A new
AttributeFilterinstance
AttributeFilter::greater_than(key, value)
Creates a filter that matches numeric attributes greater than the specified value.
Parameters:
key:&str- The attribute keyvalue:AttributeValue- The value to compare against (must be numeric)
- A new
AttributeFilterinstance
AttributeFilter::less_than(key, value)
Creates a filter that matches numeric attributes less than the specified value.
Parameters:
key:&str- The attribute keyvalue:AttributeValue- The value to compare against (must be numeric)
- A new
AttributeFilterinstance
AttributeFilter::contains(key, substring)
Creates a filter that matches string attributes containing the specified substring.
Parameters:
key:&str- The attribute keysubstring:&str- The substring to search for
- A new
AttributeFilterinstance
AttributeFilter::exists(key)
Creates a filter that matches memories where the specified attribute exists.
Parameters:
key:&str- The attribute key
- A new
AttributeFilterinstance
AttributeFilter::not_exists(key)
Creates a filter that matches memories where the specified attribute does not exist.
Parameters:
key:&str- The attribute key
- A new
AttributeFilterinstance
TemporalFilter
TheTemporalFilter class provides methods for filtering memories based on their temporal properties.
Creating Filters
TemporalFilter::before(timestamp)
Creates a filter that matches memories created before the specified timestamp.
Parameters:
timestamp:u64- The Unix timestamp
- A new
TemporalFilterinstance
TemporalFilter::after(timestamp)
Creates a filter that matches memories created after the specified timestamp.
Parameters:
timestamp:u64- The Unix timestamp
- A new
TemporalFilterinstance
TemporalFilter::between(start_timestamp, end_timestamp)
Creates a filter that matches memories created between the specified timestamps.
Parameters:
start_timestamp:u64- The start Unix timestampend_timestamp:u64- The end Unix timestamp
- A new
TemporalFilterinstance
TemporalFilter::within_last(seconds)
Creates a filter that matches memories created within the last specified number of seconds.
Parameters:
seconds:u64- Number of seconds
- A new
TemporalFilterinstance

