Preference and fact operations
Preference and fact storage/search operations from LongTermMemory API reference. Signatures show types, keyword-only arguments (*), and defaults; they are reference declarations, not calls to execute directly.
Preference operations (bolt only)
add_preference
Store a preference. Use preference, not value, as the keyword. user_identifier creates an explicit user association; applies_to targets an entity.
async def add_preference(
category: str,
preference: str,
*,
context: str | None=None,
confidence: float=1.0,
generate_embedding: bool=True,
metadata: dict[str, Any] | None=None,
user_identifier: str | None=None,
applies_to: list[Any] | None=None,
) -> Preference: ...
| Parameter | Description |
|---|---|
|
Preference category (food, music, communication, etc.) |
|
The preference statement |
|
When/where preference applies |
|
Confidence score |
|
Whether to generate embedding |
|
Optional metadata |
|
When provided, writes a |
|
Optional list of EntityRef describing the entities this preference scopes to. Each ref is materialized as a |
get_preferences_by_category
Return preferences in a category. This is the category-listing operation; get_preferences does not exist.
async def get_preferences_by_category(category: str, *, limit: int=100) -> list[Preference]: ...
| Parameter | Description |
|---|---|
|
The preference category |
|
Maximum results |
get_preferences_for
Retrieve preferences with explicit user/entity filters and optional superseded preferences.
async def get_preferences_for(
user_identifier: str,
*,
applies_to: Any | None=None,
active_only: bool=True,
as_of: datetime | None=None,
) -> list[Preference]: ...
| Parameter | Description |
|---|---|
|
The user whose preferences to return. |
|
Optional |
|
When |
|
When provided, only preferences whose validity interval contains this timestamp are returned. Implements the v0.5 bi-temporal time-travel API on top of valid_from / valid_until set by |
search_preferences
Semantic preference search. The optional category filter is not a user boundary.
async def search_preferences(
query: str,
*,
category: str | None=None,
limit: int=10,
threshold: float=0.7,
) -> list[Preference]: ...
| Parameter | Description |
|---|---|
|
Search query |
|
Optional filter by category |
|
Maximum results |
|
Minimum similarity threshold |
Fact operations (bolt only)
add_fact
Store a subject–predicate–object statement. The object parameter is named obj; validity bounds and confidence are optional.
async def add_fact(
subject: str,
predicate: str,
obj: str,
*,
confidence: float=1.0,
valid_from: datetime | None=None,
valid_until: datetime | None=None,
generate_embedding: bool=True,
metadata: dict[str, Any] | None=None,
) -> Fact: ...
| Parameter | Description |
|---|---|
|
Fact subject |
|
Fact predicate/relationship |
|
Fact object |
|
Confidence score |
|
Start of validity |
|
End of validity |
|
Whether to generate embedding |
|
Optional metadata |
get_facts_about
Return facts whose subject exactly equals subject. Facts where the name appears as the object are not returned. There is no get_facts wrapper.
async def get_facts_about(subject: str, *, limit: int=100) -> list[Fact]: ...
| Parameter | Description |
|---|---|
|
Exact subject value to match |
|
Maximum results |
Models
Import these Pydantic models from neo4j_agent_memory.memory.long_term. IDs are UUIDs, and inherited memory fields are shown below.
Preference
Pydantic model; inherited memory-entry fields are included.
| Field | Type | Default | Description |
|---|---|---|---|
|
|
|
Unique identifier. |
|
|
|
Creation time. |
|
|
|
Last update time, if updated. |
|
|
|
Embedding vector, if one was generated. |
|
|
|
Arbitrary key-value metadata, stored as JSON. |
|
|
|
Preference category |
|
|
|
The preference statement |
|
|
|
When/where preference applies |
|
|
|
Confidence score |
|
|
|
Linked entity IDs |
Fact
Pydantic model; inherited memory-entry fields are included.
| Field | Type | Default | Description |
|---|---|---|---|
|
|
|
Unique identifier. |
|
|
|
Creation time. |
|
|
|
Last update time, if updated. |
|
|
|
Embedding vector, if one was generated. |
|
|
|
Arbitrary key-value metadata, stored as JSON. |
|
|
|
Fact subject |
|
|
|
Fact predicate/relationship |
|
|
|
Fact object |
|
|
|
Confidence score |
|
|
|
Source message/document ID |
|
|
|
Start of validity |
|
|
|
End of validity |
Fact.as_triple returns (subject, predicate, object).