Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release-graphiti-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
raise SystemExit("fork wheel must contain one METADATA file")
metadata = BytesParser().parsebytes(archive.read(metadata_files[0]))
if (metadata["Name"], metadata["Version"]) != (
"archolith-graphiti-core", "0.32.1.post2"
"archolith-graphiti-core", "0.32.1.post3"
):
raise SystemExit("fork wheel name or version differs from reviewed release")
required_hooks = {
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ This file covers the Archolith maintenance fork published as
The package still imports as `graphiti_core`. For the upstream project's release
history, see [getzep/graphiti](https://github.com/getzep/graphiti/releases).

## 0.32.1.post3 — 2026-12-01

[Source tag](https://github.com/Archolith/graphiti/tree/v0.32.1.post3) ·
[PyPI files](https://pypi.org/project/archolith-graphiti-core/0.32.1.post3/)

### Added

Candidate-universe capture for replay (Archolith/menhir#469). Label: `Menhir policy divergence`.
Every default keeps the behavior of today.

- `add_episode(resolution_trace=...)`: a `ResolutionTrace` that gets the candidate pools of node and
edge resolution (empty pools too), the context episodes (`record_context_episodes`), the endpoint
lookups of edge resolution (`record_endpoint_lookup`) and the exact-name lookups
(`record_name_lookup`). Rejected with concurrent ingestion.
- `add_episode(uuid_seed=...)`: new nodes and edges get uuids from the seed and their position in
the extraction order. `None` keeps `uuid4`. Rejected with concurrent ingestion.
- `add_episode(prompt_attributes='declared')`: the dedupe candidates and the summary and attribute
prompts show only the attributes that the entity type declares. `'all'` (the default) is the
upstream behavior. Rejected with concurrent ingestion.
- A `uuid` tie-break (`ASC`) after the existing order in node and edge similarity and fulltext
search, relevant-edge and invalidation-candidate queries, `EntityNode.get_by_names`,
`EntityNode.get_by_attribute_values` and `retrieve_episodes` (after `created_at`).

## 0.31.2.post4 — 2026-11-22

[Source tag](https://github.com/Archolith/graphiti/tree/v0.31.2.post4) ·
Expand Down
82 changes: 81 additions & 1 deletion graphiti_core/graphiti.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
RELEVANT_SCHEMA_LIMIT,
get_mentioned_nodes,
)
from graphiti_core.seeded_uuids import reseed_extraction, seeded_uuid
from graphiti_core.telemetry import capture_event
from graphiti_core.tracer import Tracer, create_tracer
from graphiti_core.utils.bulk_utils import (
Expand Down Expand Up @@ -130,6 +131,7 @@
retrieve_episodes,
)
from graphiti_core.utils.maintenance.node_operations import (
PromptAttributes,
_extract_entity_summaries_batch,
_identity_type_for_node,
extract_attributes_from_nodes,
Expand Down Expand Up @@ -300,6 +302,11 @@ def _preserved_edge_attribute_names(value: Iterable[str] | None) -> frozenset[st
)


def _kwargs_if(condition: bool, **kwargs: Any) -> dict[str, Any]:
"""Keyword arguments to forward only when `condition` holds (typed for pyright)."""
return kwargs if condition else {}


class Graphiti:
# Class-level default so instances that bypass __init__ (subclasses, test
# doubles, unpickled-style instances) safely observe "no hook configured" and
Expand Down Expand Up @@ -699,11 +706,17 @@ def _reject_fork_seams_for_concurrent_ingestion(
self,
new_episode_uuid: str | None = None,
publish_fence: PublishFence | None = None,
resolution_trace: 'ResolutionTrace | None' = None,
uuid_seed: str | None = None,
prompt_attributes: PromptAttributes | None = None,
) -> None:
"""Raise when a fork seam is in use, because concurrent ingestion does not carry them."""
seams = {
'new_episode_uuid': new_episode_uuid,
'publish_fence': publish_fence,
'resolution_trace': resolution_trace,
'uuid_seed': uuid_seed,
'prompt_attributes': prompt_attributes,
'single_episode_extraction_hook': self.single_episode_extraction_hook,
'identity_gate_hook': self.identity_gate_hook,
'candidate_filter_hook': self.candidate_filter_hook,
Expand Down Expand Up @@ -1266,6 +1279,7 @@ async def _merge_materialized_endpoint_nodes(
identity_properties: dict[str, list[str]] | None = None,
clients: GraphitiClients | None = None,
trace: 'ResolutionTrace | None' = None,
prompt_attributes: PromptAttributes = 'all',
) -> None:
"""Fold endpoints materialized by ``extract_edges`` into the resolved node set.

Expand All @@ -1278,6 +1292,8 @@ async def _merge_materialized_endpoint_nodes(
clients = clients or self.clients
# Pass `trace` only when it is set, so the serial path makes the calls of today.
trace_kwargs: dict[str, Any] = {'trace': trace} if trace is not None else {}
if prompt_attributes != 'all':
trace_kwargs['prompt_attributes'] = prompt_attributes
nodes_by_name = {_normalize_string_exact(node.name): node for node in nodes}
known_uuids = {node.uuid for node in nodes}

Expand Down Expand Up @@ -1341,6 +1357,8 @@ async def _extract_and_resolve_edges(
identity_properties: dict[str, list[str]] | None = None,
clients: GraphitiClients | None = None,
trace: 'ResolutionTrace | None' = None,
uuid_seed: str | None = None,
prompt_attributes: PromptAttributes = 'all',
) -> tuple[list[EntityEdge], list[EntityEdge], list[EntityEdge]]:
"""Extract edges from episode(s) and resolve against the existing graph.

Expand Down Expand Up @@ -1387,6 +1405,14 @@ async def _extract_and_resolve_edges(
strict_edge_types,
custom_extraction_instructions,
)
if uuid_seed is not None:
# Edges and endpoint nodes of the separate route get seeded uuids in list order.
reseed_extraction(
uuid_seed,
materialized_nodes,
extracted_edges,
node_kind='endpoint',
)

# Merge only nodes that extract_edges newly materialized — never the full
# pre-resolution extracted_nodes list, which also contains deduped duplicates
Expand All @@ -1402,6 +1428,7 @@ async def _extract_and_resolve_edges(
identity_properties=identity_properties,
clients=clients,
trace=trace,
prompt_attributes=prompt_attributes,
)

edges = resolve_edge_pointers(extracted_edges, uuid_map)
Expand Down Expand Up @@ -1434,6 +1461,7 @@ async def _process_episode_data(
clients: GraphitiClients | None = None,
publish_fence: PublishFence | None = None,
previous_episode_uuids: Sequence[str] | None = None,
uuid_seed: str | None = None,
) -> tuple[list[EpisodicEdge], EpisodicNode]:
"""Process and save episode data to the graph.

Expand Down Expand Up @@ -1475,6 +1503,9 @@ async def _process_episode_data(
episode_uuids = [ep.uuid for ep in episodes]

episodic_edges = build_episodic_edges(nodes, episode_uuids, now, node_episode_index_map)
if uuid_seed is not None:
for index, episodic_edge in enumerate(episodic_edges):
episodic_edge.uuid = seeded_uuid(uuid_seed, 'episodic_edge', index)
for ep in episodes:
ep.entity_edges = [edge.uuid for edge in entity_edges]
if not self.store_raw_episode_content:
Expand Down Expand Up @@ -1977,6 +2008,9 @@ async def add_episode(
new_episode_uuid: str | None = None,
publish_fence: PublishFence | None = None,
identity_properties: dict[str, list[str]] | None = None,
resolution_trace: 'ResolutionTrace | None' = None,
uuid_seed: str | None = None,
prompt_attributes: PromptAttributes = 'all',
) -> AddEpisodeResults:
"""
Process an episode and update the graph.
Expand Down Expand Up @@ -2035,6 +2069,20 @@ async def add_episode(
identity_properties : dict[str, list[str]] | None
Optional. Map entity type names to attribute names that identify entities.
Graphiti extracts these attributes before node resolution.
resolution_trace : ResolutionTrace | None
Optional. Receives what node resolution and edge resolution read: the context
episodes, the candidate pools (empty ones too), the exact-name and endpoint
lookups, and the edge candidates. Passing it does not change the result.
Incompatible with concurrent ingestion (ValueError).
uuid_seed : str | None
Optional. When set, the uuids of the new nodes and edges of this call derive from the
seed and from the position of each item in the extraction order. When None, the
uuids are random as before. Incompatible with concurrent ingestion (ValueError).
prompt_attributes : 'all' | 'declared'
Which stored node attributes the dedupe, attribute and summary prompts show. 'all'
(default) shows every stored property. 'declared' shows only the attributes that the
entity type model of the node declares, and none for a node without a model.
Incompatible with concurrent ingestion unless 'all' (ValueError).

Returns
-------
Expand Down Expand Up @@ -2071,6 +2119,8 @@ async def add_episode_endpoint(episode_data: EpisodeData):
'publish_fence cannot be combined with saga or update_communities: '
'they write outside the publish transaction'
)
if prompt_attributes not in ('all', 'declared'):
raise ValueError("prompt_attributes must be 'all' or 'declared'")

start = time()
now = utc_now()
Expand All @@ -2090,7 +2140,13 @@ async def add_episode_endpoint(episode_data: EpisodeData):

if self._concurrent_ingestion_enabled(group_id):
# Fork seams are not supported with concurrent ingestion (fail-closed guard).
self._reject_fork_seams_for_concurrent_ingestion(new_episode_uuid, publish_fence)
self._reject_fork_seams_for_concurrent_ingestion(
new_episode_uuid,
publish_fence,
resolution_trace,
uuid_seed,
prompt_attributes if prompt_attributes != 'all' else None,
)
if update_communities:
raise ValueError(
'update_communities=True has no support in concurrent ingestion. '
Expand Down Expand Up @@ -2146,6 +2202,8 @@ async def add_episode_endpoint(episode_data: EpisodeData):
# The context episodes actually used (the parameter above is only the caller's
# request), reported to the publish fence.
fence_previous_episode_uuids = [ep.uuid for ep in previous_episodes]
if resolution_trace is not None:
resolution_trace.record_context_episodes(previous_episodes)

# Get or create episode
if uuid is not None:
Expand Down Expand Up @@ -2190,6 +2248,11 @@ async def add_episode_endpoint(episode_data: EpisodeData):
custom_extraction_instructions,
clients=clients,
)
if uuid_seed is not None:
# Seeded uuids follow the extraction order, not the order of task completion.
reseed_extraction(
uuid_seed, extracted_nodes, precomputed_edges, node_episode_index_map
)

# Hook kwargs are forwarded only when the corresponding hook is
# configured; identity_properties is always passed, as upstream does.
Expand All @@ -2204,6 +2267,15 @@ async def add_episode_endpoint(episode_data: EpisodeData):
identity_kwargs['node_pre_resolution_edges'] = precomputed_edges
identity_kwargs['identity_properties'] = identity_properties

# The seam kwargs are forwarded only when they are set, so the default path
# makes the calls of today.
trace_kwargs: dict[str, Any] = (
{'trace': resolution_trace} if resolution_trace is not None else {}
)
policy_kwargs: dict[str, Any] = (
{'prompt_attributes': prompt_attributes} if prompt_attributes != 'all' else {}
)

if identity_properties:
identity_nodes = [
node
Expand All @@ -2220,6 +2292,7 @@ async def add_episode_endpoint(episode_data: EpisodeData):
previous_episodes,
entity_types,
validate_shape=False,
**policy_kwargs,
)

nodes, uuid_map, _ = await resolve_extracted_nodes(
Expand All @@ -2229,6 +2302,8 @@ async def add_episode_endpoint(episode_data: EpisodeData):
previous_episodes,
entity_types,
**identity_kwargs,
**trace_kwargs,
**policy_kwargs,
)

# Resolve edges, carrying edges already produced by the combined
Expand All @@ -2252,6 +2327,9 @@ async def add_episode_endpoint(episode_data: EpisodeData):
precomputed_edges=precomputed_edges,
identity_properties=identity_properties,
clients=clients,
**trace_kwargs,
**policy_kwargs,
**_kwargs_if(uuid_seed is not None, uuid_seed=uuid_seed),
)

entity_edges = resolved_edges + invalidated_edges
Expand All @@ -2265,6 +2343,7 @@ async def add_episode_endpoint(episode_data: EpisodeData):
previous_episodes,
entity_types,
edges=new_edges,
**policy_kwargs,
)

# Process and save episode data (including saga association if provided)
Expand All @@ -2278,6 +2357,7 @@ async def add_episode_endpoint(episode_data: EpisodeData):
saga_previous_episode_uuid,
node_episode_index_map,
clients=clients,
**_kwargs_if(uuid_seed is not None, uuid_seed=uuid_seed),
**(
{}
if publish_fence is None
Expand Down
20 changes: 20 additions & 0 deletions graphiti_core/ingestion/change_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,28 @@ class ResolutionTrace:
ended_by_candidate: set[str] = field(default_factory=set)
# The number of model calls that node resolution made for the trace.
node_llm_calls: int = 0
# The uuids of the context (previous) episodes that the call used, in order.
context_episode_uuids: list[str] = field(default_factory=list)
# One entry for each lookup of endpoint nodes by uuid: (requested uuids, found uuids).
endpoint_lookups: list[tuple[list[str], list[str]]] = field(default_factory=list)
# One entry for each exact-name lookup: (names, group ids, found uuids in result order).
name_lookups: list[tuple[list[str], list[str], list[str]]] = field(default_factory=list)
_edge_states: dict[int, _EdgeState] = field(default_factory=dict)

def record_context_episodes(self, episodes: list[EpisodicNode]) -> None:
"""Record the context (previous) episodes that the call used. A subclass may override."""
self.context_episode_uuids = [episode.uuid for episode in episodes]

def record_endpoint_lookup(self, requested_uuids: list[str], found: list[EntityNode]) -> None:
"""Record a lookup of endpoint nodes by uuid, with an empty result too."""
self.endpoint_lookups.append((list(requested_uuids), [node.uuid for node in found]))

def record_name_lookup(
self, names: list[str], group_ids: list[str], found: list[EntityNode]
) -> None:
"""Record an exact-name node lookup (`get_by_names`), with an empty result too."""
self.name_lookups.append((list(names), list(group_ids), [node.uuid for node in found]))

def record_node_candidates(self, node_uuid: str, candidates: list[EntityNode]) -> None:
seen = self.seen_node_candidates.setdefault(node_uuid, [])
for candidate in candidates:
Expand Down
6 changes: 5 additions & 1 deletion graphiti_core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,10 @@ async def get_by_names(
AND n.name IN $names
RETURN
"""
+ get_entity_node_return_query(driver.provider),
+ get_entity_node_return_query(driver.provider)
+ """
ORDER BY n.uuid ASC
""",
names=unique_names,
group_ids=unique_group_ids,
routing_='r',
Expand Down Expand Up @@ -733,6 +736,7 @@ async def get_by_attribute_values(
"""
+ get_entity_node_return_query(driver.provider)
+ """
ORDER BY n.uuid ASC
LIMIT $limit
"""
)
Expand Down
Loading
Loading