Skip to navigation

Migrating from v3

Every v3 SDK method mapped to its v4 replacement

Most v3 methods have a direct v4 replacement. This page maps all of them for Python, TypeScript, and Go, then covers the changes that need more than a rename.

The tables match zep-cloud / @getzep/zep-cloud / zep-go v3.28.0 and the v4 alpha packages 4.0.0a5 / 4.0.0-alpha.5 / v4.0.0-alpha.5.

UUID addressing, pagination, and asynchronous deletes account for most of the work in a port. Read Identifiers, Pagination, and Deletes first.

Identifiers need to be adapted

Your existing user_id, thread_id, and graph_id values do not work the way they did in v3. You cannot pass them to get, update, delete, add_messages, or any other method that used to accept them. Those methods now take a UUID. If you pass the old identifier, the call fails.

Zep generates the UUID of every user, thread, and graph. The client addresses each resource by that UUID. A v4 create call does not accept an identifier from the client:

  • user.create does not accept a user_id.
  • thread.create does not accept a thread_id.
  • graph.create does not accept a graph_id.
  • graph.clone does not accept a target_graph_id.

A create request that contains one of these fields with a value fails with HTTP 400 and the error code invalid_request.

A resource that v4 creates has no legacy name. The v4 response for that resource contains no user_id, thread_id, or graph_id. A resource that v3 created keeps the identifier that your application gave it in v3. In v4, that identifier is a legacy name: a read-only field that you cannot change. A legacy name is not an address. Only the transitional lookup operations accept a legacy name as input.

Two reasons drive the design. Every identifier is an opaque UUID that holds no tenant, no resource type, no order, and no customer data. A customer-supplied value can hold personal data, and a value in a URL path or a query string goes into access logs, proxy logs, referrer headers, and error reports. For the same reason, each lookup operation is a POST with the identifier in the request body.

Store the UUID in your own database

Every v4 application uses the same pattern:

  1. Call user.create, thread.create, or graph.create with no identifier.
  2. Read the uuid from the response. The user.create response also contains the graph_uuid of the user graph.
  3. Write the UUID into your own table. For example, use zep_user_uuid and zep_graph_uuid columns on your users table, and a zep_thread_uuid column on the table that holds conversations.
  4. Pass the stored UUID on every later call.

Your own identifiers stay in your database, in the same row as the Zep UUID. Zep does not store them, and no Zep operation accepts them. To find the Zep resource for one of your records, read the UUID from that record.

If you need a label on a Zep user, put the label in the user metadata. A thread has no metadata field. A graph has a name and a description. The graph name is descriptive text. It is not an identifier, and no operation addresses a graph by its name.

Migrate a production application shows this pattern with code, including safe retries.

Resolve legacy names with lookup

The lookup operations resolve a legacy name to a UUID:

  • user.lookup resolves one user_id.
  • thread.lookup resolves one thread_id.
  • graph.lookup resolves one graph_id.
  • lookup.batch resolves up to 1000 identifiers of users, threads, and graphs in one request.

Use lookup only to migrate identifiers that your application stored in v3. A resource that v4 creates has no legacy name, so lookup never finds it.

Do not call lookup in the request path of your application. A lookup before every read adds a round trip to each request. Resolve each identifier one time, keep the UUID, and address the resource by UUID.

lookup is transitional. It becomes deprecated when the v3 surface retires, and a later major version removes it. Code that reads a stored UUID needs no further change.

The example below resolves many identifiers in one request. The response has one item for each identifier in the request. An identifier that does not resolve returns found: false with no UUID.

lookup = client.lookup.batch(
users=["user_1234", "user_5678"],
threads=["thread_1234"],
graphs=["support-emea"],
)
uuids = {
(item.resource_type, item.legacy_id): item.uuid_
for item in lookup.items or []
if item.found
}

The map key contains the resource type, because a user and a thread can have the same legacy name.

Migrate one call

The example below resolves one thread and then adds messages to it. The lookup is a one-time migration step. In production code, read the UUID from your own database, as the production procedure shows.

v3. thread.add_messages takes your thread_id.

from zep_cloud.types import Message
client.thread.add_messages(
thread_id="thread_1234",
messages=[
Message(role="user", name="Ada", content="I prefer window seats."),
],
)

v4. Look up the thread, then pass uuid_. Store uuid_ with your own conversation record, and read it from there on every later call. Use user.lookup(user_id=...) and graph.lookup(graph_id=...) the same way.

from zep_cloud import AddMessage
thread = client.thread.lookup(thread_id="thread_1234")
client.thread.add_messages(
thread.uuid_,
messages=[
AddMessage(role="user", name="Ada", content="I prefer window seats."),
],
)

Migrate a production application

Use this procedure when your application runs on v3 in production and must continue to create users, threads, and graphs during the migration. At the end, your application uses only v4, and it addresses every resource by a UUID that it keeps in its own database.

Two facts set the order of the steps:

  • v3 and v4 serve the same project data at the same time. A resource that v3 creates is available through v4, and v4 addresses it by UUID.
  • v3 cannot address a resource that v4 creates. v3 addresses users, threads, and graphs by the identifier that your application gave them. A resource that v4 creates has no such identifier.

For these reasons, your application moves its reads and writes to v4 first. It moves resource creation to v4 only after no v3 read or write remains.

During steps 2 to 5, your application uses the v3 SDK and the v4 SDK. The Go SDKs have different module paths (github.com/getzep/zep-go/v3 and github.com/getzep/zep-go/v4), so one Go module can import both. In TypeScript, install the v3 SDK under an alias, for example npm install zep-cloud-v3@npm:@getzep/zep-cloud@^3.30.0, and install the v4 SDK as @getzep/zep-cloud. In Python, both SDKs are the zep-cloud package, so one Python environment cannot contain both. Run the v3 calls and the v4 calls in different processes, for example in two services.

1

Add nullable UUID columns

Purpose: Give each of your records a place for the Zep UUID.

Add a nullable column for the Zep UUID to each table that refers to a Zep resource. For example:

  • Add zep_user_uuid and zep_graph_uuid to your users table.
  • Add zep_thread_uuid to the table that holds conversations.
  • Add zep_graph_uuid to each table that refers to a standalone graph.
  • Add zep_lookup_status to each table that the backfill reads. The backfill writes 'not_found' into this column and skips those rows later.

Keep your own identifier columns. They stay the key of your records.

The columns are nullable because the existing rows have no UUID yet. Step 3 fills them.

Finish this step when the columns exist in production and your application runs with the new schema.

2

Capture the UUID of every new resource

Purpose: Stop the number of rows without a UUID from growing.

Keep the v3 create calls, and keep your v3 identifiers for now. Change each create call to write the UUID from the v3 response into the new column. The v3 response already contains the UUID that v4 uses, so no lookup is necessary. Use v3 SDK version 3.30.0 or later, which exposes the graph fields below.

v3 create callValue to storeColumn
user.adduuidzep_user_uuid
user.addgraph_uuidzep_graph_uuid on the user row
thread.createuuidzep_thread_uuid
graph.createcanonical_graph_uuidzep_graph_uuid

Do not store the v3 Graph.uuid. That value identifies an internal group record, and v4 does not accept it as a graph UUID. v4 addresses a graph by the value that v3 returns as canonical_graph_uuid. User and thread UUIDs have the same value in v3 and v4.

A v3 graph.clone response contains the identifiers of the target, not a UUID. After a clone into a standalone graph, call graph.get on v3 with the target graph_id, and store its canonical_graph_uuid. After a clone into a user graph, call user.get on v3 with the target user_id, and store its graph_uuid.

The graph fields are empty when the graph record does not exist yet. In that case, write NULL. The backfill in step 3 fills the value.

from zep_cloud.client import Zep # zep-cloud 3.30.0 or later (v3)
zep_v3 = Zep(api_key=ZEP_API_KEY)
def create_user(db, user_id: str, email: str) -> None:
user = zep_v3.user.add(user_id=user_id, email=email)
db.execute(
"UPDATE users SET zep_user_uuid = %s, zep_graph_uuid = %s WHERE id = %s",
(user.uuid_, user.graph_uuid, user_id),
)
def create_conversation(db, conversation_id: str, user_id: str) -> None:
thread = zep_v3.thread.create(thread_id=conversation_id, user_id=user_id)
db.execute(
"UPDATE conversations SET zep_thread_uuid = %s WHERE id = %s",
(thread.uuid_, conversation_id),
)
def create_team_graph(db, team_id: str) -> None:
graph = zep_v3.graph.create(graph_id=team_id, name="Team knowledge")
db.execute(
"UPDATE teams SET zep_graph_uuid = %s WHERE id = %s",
(graph.canonical_graph_uuid, team_id),
)

Finish this step when the new code runs on every instance of your application. From this point, each new row gets its UUID at creation time.

3

Backfill the existing rows

Purpose: Give every row that existed before step 2 its UUID.

Run a job outside your request path. The job uses the v4 SDK:

  1. Read up to 1000 rows that have no UUID. Order the rows by your own identifier, and continue after the last identifier of the previous page.
  2. Call lookup.batch with the identifiers of those rows. One request accepts up to 1000 identifiers in total across users, threads, and graphs. Do not put the same identifier two times in one list.
  3. For each item with found: true, write the uuid into the row. Write only when the column is still NULL, so that the job never changes a value that step 2 wrote.
  4. For each item with found: false, record the row as not found, for example in a zep_lookup_status column. The job does not read these rows again.
  5. Continue with the next page until no row remains.

lookup.batch returns only the UUID of each user. To fill zep_graph_uuid on the users table, call user.get on v4 for each user that has a zep_user_uuid and no zep_graph_uuid, and store the graph_uuid of the response. For graphs, lookup.batch returns the UUID that v4 uses.

The job is safe to run again. It reads only rows without a UUID and rows that are not marked as not found. It writes only to empty columns. If the job stops, start it again from the beginning.

An item with found: false means that the identifier does not resolve for the API key. The resource does not exist in the project of the key, the resource was deleted, or the key cannot read the resource. Examine each of these rows. Then create the resource again with the code from step 2, or remove the reference to Zep from the row.

Send one lookup request at a time. When Zep limits the request rate, a request fails with HTTP 429, the error code rate_limited, and a Retry-After header that gives the number of seconds to wait. The SDKs retry HTTP 429 automatically. If the error still reaches your job, wait the number of seconds in Retry-After, and send the same request again.

A request that fails with HTTP 403 permission_denied or HTTP 503 service_unavailable did not resolve any identifier. Do not mark rows as not found for this failure. Stop the job, correct the cause, and run the job again.

import time
from zep_cloud.client import Zep # v4
from zep_cloud.core.api_error import ApiError
zep = Zep(api_key=ZEP_API_KEY)
PAGE_SIZE = 1000
def backfill_users(db) -> None:
last_id = ""
while True:
rows = db.fetch_all(
"SELECT id FROM users"
" WHERE zep_user_uuid IS NULL AND zep_lookup_status IS NULL AND id > %s"
" ORDER BY id LIMIT %s",
(last_id, PAGE_SIZE),
)
if not rows:
return
ids = [row.id for row in rows]
result = lookup_with_retry(ids)
for item in result.items or []:
if item.found:
db.execute(
"UPDATE users SET zep_user_uuid = %s"
" WHERE id = %s AND zep_user_uuid IS NULL",
(item.uuid_, item.legacy_id),
)
else:
db.execute(
"UPDATE users SET zep_lookup_status = 'not_found' WHERE id = %s",
(item.legacy_id,),
)
last_id = ids[-1]
def lookup_with_retry(ids: list[str]):
while True:
try:
return zep.lookup.batch(users=ids)
except ApiError as err:
if err.status_code != 429:
raise # 403 and 503 stop the job. No row is marked.
time.sleep(int((err.headers or {}).get("retry-after", "1")))

The examples show the users table. Run the same job for your conversation table with threads, and for your graph tables with graphs.

Finish this step when the job finds no row without a UUID, and you resolved every row that is marked as not found.

4

Move reads and writes to v4

Purpose: Remove every v3 call that reads or changes an existing resource.

Change each read and write call to v4, and pass the stored UUID. Use the method map for the v4 method, and read Changes that need more than a rename for the changes in behavior. Keep the v3 create calls from step 2.

Put the v4 code behind a feature flag, or roll it out to a part of your traffic at a time. v3 and v4 use the same data, so a message that v3 adds is available on v4, and the reverse is also true. You can move the traffic back to v3 during this step, because every resource still has its v3 identifier.

A row can have no UUID at this time, for example when step 3 did not process the row. Do not call lookup in the request path for that row. Resolve the row outside the request path: send it to a background task that calls user.lookup, thread.lookup, or graph.lookup one time and writes the UUID into the row, or run the step 3 job again. Until the row has its UUID, serve that request with the v3 code. This safety net is temporary. Remove it in step 6.

Finish this step when all of your traffic uses the v4 code for reads and writes, the only remaining v3 calls are the create calls, and the safety net resolved no row for a period that you choose, for example one week.

5

Move resource creation to v4

Purpose: Create new users, threads, and graphs on v4, with no identifier.

Change each create call to v4. Send no user_id, thread_id, graph_id, or target_graph_id. Read the UUID from the response, and store it in the row:

v4 create callValue to storeColumn
user.createuuidzep_user_uuid
user.creategraph_uuidzep_graph_uuid on the user row
thread.create (takes the user_uuid)uuidzep_thread_uuid
graph.createuuidzep_graph_uuid
graph.clone (takes the source graph_uuid, no target)graph.uuidzep_graph_uuid of the copy

A create call is a network call, so do not keep a database transaction open while it runs. Use this order of operations:

  1. Insert your row with the Zep UUID column set to NULL.
  2. Call the v4 create with the profile fields, such as the email address.
  3. Write the UUID from the response into the row.

If the process stops after step 1 or step 2, the row has a NULL UUID. A repair task finds these rows and repeats steps 2 and 3.

The SDK sends an idempotency key on its own retries, so a retried request does not make a second resource. A create that your application repeats, such as the repair task after a stop between steps 2 and 3, makes a second user. To prevent that, you can pass an optional idempotency key that you store with the row. See Repeated creates.

This order prevents orphans. If you create the Zep resource before you insert your row, and the insert fails, no row refers to the Zep resource.

from zep_cloud.client import Zep # v4
zep = Zep(api_key=ZEP_API_KEY)
def create_user(db, user_id: str, email: str) -> None:
db.execute(
"INSERT INTO users (id, email) VALUES (%s, %s)",
(user_id, email),
)
provision_zep_user(db, user_id)
def provision_zep_user(db, user_id: str) -> None:
"""Called at creation time, and again by the repair task."""
row = db.fetch_one(
"SELECT email FROM users WHERE id = %s", (user_id,)
)
user = zep.user.create(email=row.email)
db.execute(
"UPDATE users SET zep_user_uuid = %s, zep_graph_uuid = %s"
" WHERE id = %s AND zep_user_uuid IS NULL",
(user.uuid_, user.graph_uuid, user_id),
)
def provision_zep_thread(db, conversation_id: str) -> None:
row = db.fetch_one(
"SELECT u.zep_user_uuid FROM conversations c"
" JOIN users u ON u.id = c.user_id WHERE c.id = %s",
(conversation_id,),
)
thread = zep.thread.create(user_uuid=row.zep_user_uuid)
db.execute(
"UPDATE conversations SET zep_thread_uuid = %s"
" WHERE id = %s AND zep_thread_uuid IS NULL",
(thread.uuid_, conversation_id),
)

Use the same pattern for graph.create and graph.clone. A clone request has no body fields: Zep creates the target graph, and the response contains the new graph and a task. The response contains the UUID of the copy at once, so store it before the task completes. See Cloning graphs.

Do not move reads or writes back to v3 after this step starts. v3 cannot address a resource that v4 created.

Finish this step when your application sends no v3 create call, and the repair task finds no row that has a NULL UUID.

6

Remove v3 and lookup

Purpose: Leave only the long-term pattern in your application.

Remove these items from your application:

  • The v3 SDK and every v3 code path.
  • Every lookup call, including the safety net from step 4.
  • The backfill job from step 3.

Keep the repair task from step 5. It is part of the create pattern.

Keep your own identifiers in your own database, next to the Zep UUIDs. A resource that v3 created still has its legacy name as a read-only field. Do not use that field to find a resource. Read the UUID from your own record.

Finish this step when a search of your code finds no v3 SDK import and no lookup call.

Method map

Use the language tab that matches your SDK. Each row is one v3 method.

TypeScript POST list and search methods take pagination on the request object and the JSON body under body. The SDK throws JsonError: Expected object when body is missing. Use { limit: 1, body: {} } for an unfiltered list and { limit: 1, body: { query: "..." } } for search. Filter keys in that body stay snake_case (connected_node_uuids), because filters is an untyped object.

Go search methods put the query on Body, for example GraphSearchEdgesRequest{Body: &SearchRequest{Query: "..."}}. Artifact list Filters is map[string]any. Use the snake_case keys connected_node_uuids, mentioned_node_uuids, and episode_uuids.

Users

v3v4
user.adduser.create (no user_id)
user.list_ordereduser.list
user.getuser.get (takes user_uuid)
user.updateuser.update (takes user_uuid)
user.deleteuser.delete (takes user_uuid; returns a task)
user.get_nodeuser.get_node (takes user_uuid)
user.get_threadsthread.list(user_uuid=)
user.warmgraph.warm(graph_uuid=user.graph_uuid)
user.list_user_summary_instructionsuser.get_summary_instructions, or project.get_user_summary_instructions
user.add_user_summary_instructionsuser.set_summary_instructions, or project.set_user_summary_instructions (writes the whole set)
user.delete_user_summary_instructionsuser.set_summary_instructions, or project.set_user_summary_instructions (writes the whole set)

Threads

v3v4
thread.createthread.create (requires user_uuid, no thread_id)
thread.deletethread.delete (takes thread_uuid; returns a task)
thread.list_allthread.list
thread.get (returns messages)thread.list_messages. thread.get in v4 returns the thread record.
thread.add_messagesthread.add_messages (takes thread_uuid)
thread.add_messages_batchbatch.create, then batch.add_items, then batch.process
thread.get_user_contextthread.get_context
thread.get_summarythread.get_summary
thread.message.updatethread.message.update (takes thread_uuid and message_uuid)

Graphs and ingestion

v3v4
graph.creategraph.create (no graph_id)
graph.getgraph.get (takes graph_uuid)
graph.updategraph.update (takes graph_uuid)
graph.deletegraph.delete (takes graph_uuid; returns a task)
graph.list_allgraph.list
graph.warmgraph.warm (takes graph_uuid)
graph.clonegraph.clone (source graph_uuid, no target)
graph.addgraph.episode.add
graph.add_batchbatch.create, then batch.add_items, then batch.process
graph.add_nodesgraph.node.add
graph.add_fact_triplegraph.edge.add
graph.get_subgraphgraph.get_subgraph
graph.detect_patternsremoved

Search and context

v3v4
graph.search with scope edgesgraph.search_edges
graph.search with scope nodesgraph.search_nodes
graph.search with scope episodesgraph.search_episodes
graph.search with scope observationsgraph.search_observations
graph.search with scope thread_summariesgraph.search_thread_summaries
graph.search with scope autograph.get_context

Graph artifacts

v3v4
graph.edge.get_by_graph_idgraph.edge.list
graph.edge.get_by_user_idgraph.edge.list
graph.edge.getgraph.edge.get (also requires graph_uuid)
graph.edge.updategraph.edge.update (also requires graph_uuid)
graph.edge.deletegraph.edge.delete (also requires graph_uuid; returns a task)
graph.node.get_by_graph_idgraph.node.list
graph.node.get_by_user_idgraph.node.list
graph.node.getgraph.node.get (also requires graph_uuid)
graph.node.updategraph.node.update (also requires graph_uuid)
graph.node.deletegraph.node.delete (also requires graph_uuid; returns a task)
graph.node.get_edgesgraph.edge.list with filters.connected_node_uuids
graph.node.get_episodesgraph.episode.list with filters.mentioned_node_uuids
graph.node.get_neighborsgraph.node.list_neighbors
graph.episode.get_by_graph_idgraph.episode.list
graph.episode.list_by_graph_idgraph.episode.list
graph.episode.get_by_user_idgraph.episode.list
graph.episode.list_by_user_idgraph.episode.list
graph.episode.getgraph.episode.get (also requires graph_uuid)
graph.episode.updategraph.episode.update (also requires graph_uuid)
graph.episode.deletegraph.episode.delete (also requires graph_uuid; returns a task)
graph.episode.get_nodes_and_edgesgraph.node.list and graph.edge.list with filters.episode_uuids
graph.observation.get_by_graph_idgraph.observation.list
graph.observation.get_by_user_idgraph.observation.list
graph.observation.getgraph.observation.get (also requires graph_uuid)
graph.thread_summary.get_by_graph_idgraph.thread_summary.list
graph.thread_summary.get_by_user_idgraph.thread_summary.list

Configuration

v3v4
graph.list_entity_typesgraph.get_ontology, or project.get_ontology
graph.set_entity_types_internalgraph.set_ontology, or project.set_ontology
graph.set_entity_typesgraph.set_ontology, or project.set_ontology
graph.set_ontologygraph.set_ontology, or project.set_ontology
zep_cloud.external_clients.ontology (EntityModel, EdgeModel, EntityText)zep_cloud.ontology (EntityModel, EdgeModel, EntityText, build_ontology); pass the entity_types and edge_types that build_ontology returns to set_ontology
graph.list_custom_instructionsgraph.get_instructions, or project.get_instructions
graph.add_custom_instructionsgraph.set_instructions, or project.set_instructions (writes the whole set)
graph.delete_custom_instructionsgraph.set_instructions, or project.set_instructions (writes the whole set)
project.getproject.get
project.updateproject.update
project.get_observation_steeringproject.get_observation_steering, or graph.get_observation_steering
project.set_observation_steeringproject.set_observation_steering, or graph.set_observation_steering
context.list_context_templatescontext.list_templates (filter with name, not search)
context.create_context_templatecontext.create_template
context.get_context_templatecontext.get_template
context.update_context_templatecontext.update_template
context.delete_context_templatecontext.delete_template

Batches, tasks, and user groups

v3v4
batch.listbatch.list
batch.createbatch.create
batch.getbatch.get
batch.deletebatch.delete
batch.list_itemsbatch.list_items
batch.addbatch.add_items
batch.processbatch.process
task.gettask.get
user_group.listuser_group.list
user_group.createuser_group.create
user_group.getuser_group.get
user_group.deleteuser_group.delete
user_group.updateuser_group.update
user_group.list_for_useruser_group.list_for_user
user_group.list_membersuser_group.list_members
user_group.add_membersuser_group.add_members
user_group.remove_membersuser_group.remove_members
user_group.remove_memberuser_group.remove_member
user_group.list_member_candidatesuser_group.list_member_candidates
user_group.list_policy_setsno v4 equivalent. Manage policy sets in the Zep dashboard.
user_group.attach_policy_setno v4 equivalent. Manage policy sets in the Zep dashboard.
user_group.detach_policy_setno v4 equivalent. Manage policy sets in the Zep dashboard.

New in v4

These methods have no v3 counterpart.

  • user.lookup, thread.lookup, graph.lookup, lookup.batch
  • thread.get (thread record by UUID)
  • thread.list_episodes
  • thread.message.get
  • task.list
  • graph.document_summary.list
  • graph.episode.list_for_document

Changes that need more than a rename

Pagination

Loops written against page_number or lastn, or against the Zep-Next-Cursor header, do not port. Replace them with the SDK pager. The pager walks an opaque cursor. Do not increment a page number.

v3. Advance page_number until a page is empty.

page_number = 1
while True:
page = client.user.list_ordered(page_number=page_number, page_size=50)
users = page.users or []
if not users:
break
for user in users:
print(user.user_id)
page_number += 1

v4. Iterate the pager. lastn episode reads become graph.episode.list.

for user in client.user.list(limit=50):
print(user.user_id)

Deletes

A delete returns a task rather than a success envelope. The resource is not gone when the call returns. Poll the returned task until it reaches succeeded, partial, or failed. Bound the wait. Treat a missing status as not finished.

v3. The call returns a success envelope. The next line can assume the user is gone.

client.user.delete("user_1234")

v4. Delete by UUID, then poll the task.

import time
TERMINAL = {"succeeded", "partial", "failed"}
deadline = time.monotonic() + 600
result = client.user.delete(user.uuid_)
task = client.task.get(result.task.uuid_)
while task.status not in TERMINAL:
if time.monotonic() > deadline:
raise TimeoutError(f"task {result.task.uuid_} is still {task.status}")
time.sleep(1)
task = client.task.get(result.task.uuid_)

Instruction updates

v3 added and deleted individual instructions by name. v4 reads and writes the whole set. An update is a read, a change, and a write. A write that omits an existing name removes that instruction.

v3. Add or delete one instruction by name. Other instructions stay in place.

from zep_cloud import CustomInstruction
client.graph.add_custom_instructions(
instructions=[
CustomInstruction(name="tone", text="Prefer concise facts."),
]
)
client.graph.delete_custom_instructions(instruction_names=["tone"])

v4. Read the current list, change it, and write the full list back. project.set_instructions sets the project default. graph.set_instructions sets one graph.

from zep_cloud import CustomInstruction
current = client.project.get_instructions()
updated = [i for i in (current.instructions or []) if i.name != "tone"]
updated.append(CustomInstruction(name="tone", text="Prefer concise facts."))
client.project.set_instructions(instructions=updated)

Declaring entity and edge types in code

v3 took your model classes or structs and derived the payload inside the SDK call. v4 separates the two steps. You declare the types with the SDK ontology helpers, you build the payload, and you pass the payload to graph.set_ontology or project.set_ontology. The helper names changed with the step:

Languagev3v4
Pythonzep_cloud.external_clients.ontologyzep_cloud.ontology (EntityModel, EdgeModel, EntityText), and build_ontology
TypeScriptentityFieldsentityFields, and buildOntology
Gozep.BaseEntity, zep.BaseEdgezep.EntityBase, zep.EdgeBase, zep.Entities, zep.Edges, and zep.BuildOntology

The v3 Python module zep_cloud.external_clients.ontology does not exist in v4. Import the models and build_ontology from zep_cloud.ontology. The builder returns the payload. It does not call the API. build_ontology returns the entity_types list and the edge_types list. buildOntology and zep.BuildOntology return one Ontology object.

A type name is now a key of the builder input, not a struct tag or a class name. A property that tells two nodes of the same type apart is marked as an identity property in the declaration.

v3. graph.set_ontology took the model classes.

from pydantic import Field
from zep_cloud.external_clients.ontology import EntityModel, EntityText
class Traveler(EntityModel):
"""Someone who takes trips."""
home_city: EntityText = Field(description="The city they live in", default=None)
client.graph.set_ontology(entities={"Traveler": Traveler})

v4. Import the models from zep_cloud.ontology, call build_ontology, and pass the two lists it returns.

from pydantic import Field
from typing_extensions import Annotated
from zep_cloud.ontology import EntityModel, EntityText, Identity, build_ontology
class Traveler(EntityModel):
"""Someone who takes trips."""
home_city: Annotated[EntityText, Identity] = Field(
default=None, description="The city they live in"
)
entity_types, edge_types = build_ontology(entities={"Traveler": Traveler})
client.graph.set_ontology(
graph_uuid,
entity_types=entity_types,
edge_types=edge_types,
)

An edge type is declared the same way. Use EdgeModel in Python, an edge declaration with sourceTargets in TypeScript, and zep.EdgeBase with zep.Edges in Go. Give each edge type the entity type pairs it connects.

Ontology across many graphs

v3 applied one ontology to many graphs in a single call. v4 has one ontology operation per scope. Set the project ontology once for a shared default, or loop over the graphs that need an override.

v3. One call can target many user_ids and graph_ids.

client.graph.set_ontology(
user_ids=["user_1234", "user_5678"],
graph_ids=["support-kb", "sales-kb"],
entities=entities,
edges=edges,
)

v4. Set the project default, or call graph.set_ontology once per graph UUID.

client.project.set_ontology(entity_types=entity_types, edge_types=edge_types)
for graph_uuid in graph_uuids:
client.graph.set_ontology(
graph_uuid,
entity_types=entity_types,
edge_types=edge_types,
)

List filters

v3 had one artifact getter per scope, and a getter took no filter. v4 has one list per artifact type, and the list takes a filters object in the request body. The server applies the object, and combines each key with the scope of the list with a logical AND.

The SDK types filters as a free-form object in all three languages: Dict[str, Any] in Python, Record<string, unknown> in TypeScript, and map[string]any in Go. A key is therefore checked by the server, not by the compiler or the type checker. Three rules apply:

  • A key that no filter defines gets HTTP 400 with the code unsupported_filter and the name of the key.
  • A key that the result type cannot enforce gets the same error. graph.edge.list is the only list that takes connected_node_uuids, source_node_uuids, and target_node_uuids, because the other lists return no edges. graph.observation.list, graph.thread_summary.list, and graph.document_summary.list also reject episode_uuids, because an observation and a summary are never in the mention set of an episode.
  • metadata_filters selects results whose associated episodes’ stored metadata matches the filter. The episode_metadata_filters name from earlier revisions is rejected: rename the key.

graph.node.list takes episode_uuids, which selects the nodes that the listed episodes mention. graph.episode.list takes mentioned_node_uuids and the metadata filter, and rejects every other key.

Searching for a name

The user, graph, and context template lists are POST .../list with the filter term in the body. A term you search by is customer data, and a query string is logged. Pass the term on the SDK list call. Do not put the term in a URL.

v3. graph.list_all sent search as a query parameter.

page = client.graph.list_all(search="EMEA support", page_number=1, page_size=20)

v4. graph.list puts search in the request body. Iterate the pager.

for graph in client.graph.list(search="EMEA support", limit=20):
print(graph.uuid_, graph.name)

user.list and graph.list take the same search field. context.list_templates has no search field. It takes name, which selects the template with that exact name.

Recency bias

v3 accepted a recency_bias object on graph.search with scope auto. v4 takes a preset of off, mild, or strong on graph.get_context. There is no object with strength, half-lives, or per-scope bands.

v3. Auto search accepted a recency_bias object.

result = client.graph.search(
user_id="user_1234",
query="recent account issues",
scope="auto",
recency_bias={"strength": 0.8},
)

v4. Assemble context with a preset.

result = client.graph.get_context(
user.graph_uuid,
query="recent account issues",
recency_bias="strong",
)

Document identifiers

v4 rejects a document_id that contains /, ?, #, or an ASCII control character, and rejects a whitespace-only value. v3 accepted any string of 1 to 100 characters.

Repeated creates

In v3, a retried create with the same identifier failed because the identifier was already in use. v4 creates carry no identifier, so each create call makes a new resource. The SDK sends an idempotency key on its own retries, so a retried request does not make a second resource. You can also pass an Idempotency-Key on a create that your application can repeat. See Move resource creation to v4 for the pattern.

Defaults and caps

Search limit defaults to 50, where v3 defaulted to 10. The maximum is 50 in both. A graph artifact list defaults to 50 with a maximum of 100.

What has no v4 equivalent

  • graph.detect_patterns / graph.detectPatterns / Graph.DetectPatterns. The experimental endpoint is removed.
  • User-group policy sets (list_policy_sets, attach_policy_set, detach_policy_set and the TypeScript / Go equivalents). Manage policy sets from the Zep dashboard.