Skip to content

Commit 66df59a

Browse files
Update graph.add docstring (#256)
* SDK regeneration * SDK regeneration * chore: Version bump * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * chore: Version bump * poetry lock * chore: version bump * SDK regeneration * chore: Version bump * SDK regeneration * chore: version bump * SDK regeneration * SDK regeneration * SDK regeneration * feat: Customer provided entity types * fix * chore: version bump * SDK regeneration * fix * chore: Support entity class descriptor * SDK regeneration * fix: linter errors * chore: Version bump * SDK regeneration * SDK regeneration * SDK regeneration * chore: version bump * chore: revert unintended changes * chore: Version bump * SDK regeneration * chore: Fix fact ratings table * chore: Version bump * SDK regeneration * chore: Version bump * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * chore: Version bump * SDK regeneration * chore: Version bump * SDK regeneration * chore: regenerate poetry file * Remove pydantic version check and update mypy to 1.9.0 * chore: Bump version * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * SDK regeneration * chore: Bump version * SDK regeneration --------- Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
1 parent 58d382c commit 66df59a

File tree

7 files changed

+178
-69
lines changed

7 files changed

+178
-69
lines changed

examples/chat_history/memory.py

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from chat_history_shoe_purchase import history
2121

2222
from zep_cloud.client import AsyncZep
23-
from zep_cloud.types import Message
23+
from zep_cloud.types import Message, FactRatingInstruction, FactRatingExamples
2424

2525
load_dotenv(
2626
dotenv_path=find_dotenv()
@@ -36,17 +36,25 @@ async def main() -> None:
3636

3737
# Create a user
3838
user_id = uuid.uuid4().hex # unique user id. can be any alphanum string
39-
39+
fact_rating_instruction = """Rate the facts by poignancy. Highly poignant
40+
facts have a significant emotional impact or relevance to the user.
41+
Facts with low poignancy are minimally relevant or of little emotional
42+
significance."""
43+
fact_rating_examples = FactRatingExamples(
44+
high="The user received news of a family member's serious illness.",
45+
medium="The user completed a challenging marathon.",
46+
low="The user bought a new brand of toothpaste.",
47+
)
4048
await client.user.add(
4149
user_id=user_id,
4250
email="user@example.com",
4351
first_name="Jane",
4452
last_name="Smith",
4553
metadata={"vip": "true"},
4654
)
55+
4756
# await asyncio.sleep(1)
4857
print(f"User added: {user_id}")
49-
5058
session_id = uuid.uuid4().hex # unique session id. can be any alphanum string
5159

5260
# Create session associated with the above user
@@ -106,50 +114,6 @@ async def main() -> None:
106114

107115
print(f"Memory context: {memory.context}")
108116

109-
# Search Memory for session
110-
query = "What are Jane's favorite shoe brands?"
111-
print(f"\n---Searching over summaries for: '{query}'")
112-
summary_result = await client.memory.search_sessions(
113-
session_ids=[session_id], text=query, search_scope="summary"
114-
)
115-
print("summaryResult: ", summary_result)
116-
117-
query = "What are Jane's favorite shoe brands?"
118-
print(f"\n---Searching over facts for: '{query}'")
119-
facts_result = await client.memory.search_sessions(
120-
user_id=user_id, text=query, search_scope="facts"
121-
)
122-
print("facts_result: ", facts_result)
123-
124-
print("\n---Searching over summaries with MMR Reranking")
125-
summary_mmr_result = await client.memory.search_sessions(
126-
session_ids=[session_id], text=query, search_scope="summary", search_type="mmr"
127-
)
128-
print("summary_mmr_result: ", summary_mmr_result)
129-
130-
print("\n---Searching over messages using a metadata filter")
131-
132-
messages_result = await client.memory.search_sessions(
133-
session_ids=[session_id],
134-
text=query,
135-
search_scope="messages",
136-
record_filter={"where": {"jsonpath": '$[*] ? (@.bar == "foo")'}},
137-
)
138-
print("messages_result: ", messages_result)
139-
140-
user_messages_result = await client.memory.search_sessions(
141-
limit=3,
142-
user_id=user_id,
143-
text=query,
144-
search_scope="messages",
145-
)
146-
print("user_messages_result: ", user_messages_result)
147-
148-
# End session - this will trigger summarization and other background tasks on the completed session
149-
# Uncomment to run
150-
# print(f"\n5---end_session for Session: {session_id}")
151-
# await client.memory.end_session(session_id)
152-
153117
# Delete Memory for session
154118
# Uncomment to run
155119
# print(f"\n6---deleteMemory for Session: {session_id}")

examples/graph_example/entity_types.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,10 @@ class Purchase(EntityModel):
3939
default=None
4040
)
4141
await client.graph.set_entity_types(
42-
entities={
43-
"Purchase": Purchase,
44-
}
42+
entities={}
4543
)
46-
search_results = await client.graph.search(
47-
user_id="<user_id>",
48-
query="tickets for the concert",
49-
scope="nodes",
50-
search_filters=SearchFilters(
51-
node_labels=["Purchase"]
52-
)
53-
)
54-
print("search_results", search_results)
55-
purchases = [Purchase(**purchase_node.attributes) for purchase_node in search_results.nodes]
56-
print(purchases)
44+
enntl = await client.graph.list_entity_types()
45+
print(enntl)
5746

5847

5948
if __name__ == "__main__":
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
"""
2+
Example of using Zep Graph API to create a concert ticket purchasing scenario.
3+
This playground demonstrates user interactions with a ticket sales system,
4+
mixing chat messages and purchase events to build a knowledge graph.
5+
"""
6+
7+
import asyncio
8+
import os
9+
import uuid
10+
import json
11+
from dotenv import find_dotenv, load_dotenv
12+
13+
from zep_cloud.client import AsyncZep
14+
from zep_cloud.types import Message
15+
16+
load_dotenv(dotenv_path=find_dotenv())
17+
18+
API_KEY = os.environ.get("ZEP_API_KEY") or "YOUR_API_KEY"
19+
20+
async def create_ticket_playground() -> None:
21+
client = AsyncZep(api_key=API_KEY)
22+
23+
# Create a user for the playground
24+
user_id = uuid.uuid4().hex
25+
await client.user.add(user_id=user_id, first_name="Sarah", last_name="Smith", email="sarah.smith@example.com")
26+
print(f"Created playground user: {user_id}")
27+
28+
29+
# Sample user interactions and system events
30+
episodes = [
31+
{
32+
"type": "message",
33+
"data": "Sarah (user): Hi, I'm looking for Taylor Swift concert tickets in New York, I am a huge fan!"
34+
},
35+
{
36+
"type": "json",
37+
"data": {
38+
"event_type": "search_performed",
39+
"user_id": user_id,
40+
"artist": "Taylor Swift",
41+
"location": "New York",
42+
"date_range": "2024-07",
43+
"timestamp": "2024-01-15T10:30:00Z"
44+
}
45+
},
46+
{
47+
"type": "message",
48+
"data": "TickerSalesBot (assistant): Hi Sarah, welcome to the TicketSales. I found 2 Taylor Swift concerts at Madison Square Garden on July 15 and 16, 2024. Tickets start at $199."
49+
},
50+
{
51+
"type": "message",
52+
"data": "Sarah (user): Great! I'd like 2 tickets for July 15th please."
53+
},
54+
{
55+
"type": "json",
56+
"data": {
57+
"event_type": "ticket_purchase",
58+
"user_id": user_id,
59+
"email": "sarah.smith@example.com",
60+
"concert_id": "TS-MSG-0715",
61+
"artist": "Taylor Swift",
62+
"venue": "Madison Square Garden",
63+
"date": "2024-07-15",
64+
"quantity": 2,
65+
"seat_type": "Floor",
66+
"price_per_ticket": 199,
67+
"total_amount": 398,
68+
"transaction_id": "TRX-12345",
69+
"purchase_timestamp": "2024-01-15T10:35:00Z"
70+
}
71+
},
72+
{
73+
"type": "message",
74+
"data": "Sarah (user): Are there any upcoming Arctic Monkeys concerts?"
75+
},
76+
{
77+
"type": "json",
78+
"data": {
79+
"event_type": "search_performed",
80+
"user_id": user_id,
81+
"artist": "Arctic Monkeys",
82+
"timestamp": "2024-01-15T10:40:00Z"
83+
}
84+
},
85+
{
86+
"type": "message",
87+
"data": "TickerSalesBot (assistant): Yes! Arctic Monkeys are playing at Barclays Center on August 5th, 2024."
88+
},
89+
{
90+
"type": "message",
91+
"data": "Sarah (user): Can you add me to the waitlist for that concert?"
92+
},
93+
{
94+
"type": "json",
95+
"data": {
96+
"event_type": "waitlist_addition",
97+
"user_id": user_id,
98+
"concert_id": "AM-BC-0805",
99+
"artist": "Arctic Monkeys",
100+
"venue": "Barclays Center",
101+
"date": "2024-08-05",
102+
"timestamp": "2024-01-15T10:42:00Z"
103+
}
104+
},
105+
{
106+
"type": "message",
107+
"data": "System Notification - Arctic Monkeys tickets are now available for waitlist members!"
108+
},
109+
{
110+
"type": "json",
111+
"data": {
112+
"event_type": "ticket_purchase",
113+
"user_id": user_id,
114+
"concert_id": "AM-BC-0805",
115+
"artist": "Arctic Monkeys",
116+
"venue": "Barclays Center",
117+
"date": "2024-08-05",
118+
"quantity": 1,
119+
"seat_type": "General Admission",
120+
"price_per_ticket": 150,
121+
"total_amount": 150,
122+
"transaction_id": "TRX-12346",
123+
"purchase_timestamp": "2024-01-15T14:20:00Z"
124+
}
125+
}
126+
]
127+
128+
# Add all episodes to the graph
129+
for episode in episodes:
130+
if episode["type"] == "json":
131+
await client.graph.add(
132+
user_id=user_id,
133+
type="json",
134+
data=json.dumps(episode["data"]),
135+
)
136+
else: # message type
137+
await client.graph.add(
138+
user_id=user_id,
139+
type="message",
140+
data=episode["data"],
141+
)
142+
143+
print("Added all ticket purchase episodes to the graph")
144+
print("Waiting for graph processing...")
145+
await asyncio.sleep(30)
146+
147+
episodes = await client.graph.episode.get_by_user_id(user_id=user_id)
148+
print(episodes)
149+
150+
151+
return user_id
152+
153+
if __name__ == "__main__":
154+
user_id = asyncio.run(create_ticket_playground())
155+
print(f"\nPlayground ready! User ID: {user_id}")
156+
print("You can now explore the ticket purchase graph and add new episodes!")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "zep-cloud"
3-
version = "2.12.2"
3+
version = "2.12.3"
44
description = ""
55
readme = "README.md"
66
authors = []

reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ client.graph.set_entity_types_internal()
12171217
<dl>
12181218
<dd>
12191219

1220-
Add data to the graph. Note: each subscription tier has different limits on the amount of data that can be added to the graph please refer to the pricing page for more information.
1220+
Add data to the graph.
12211221
</dd>
12221222
</dl>
12231223
</dd>
@@ -1328,7 +1328,7 @@ client.graph.add(
13281328
<dl>
13291329
<dd>
13301330

1331-
Add data to the graph in batch mode (each episode processed concurrently). Note: each subscription tier has different limits on the amount of data that can be added to the graph please refer to the pricing page for more information.
1331+
Add data to the graph in batch mode, processing episodes concurrently. Use only for data that is insensitive to processing order.
13321332
</dd>
13331333
</dl>
13341334
</dd>

src/zep_cloud/core/client_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_headers(self) -> typing.Dict[str, str]:
1717
headers: typing.Dict[str, str] = {
1818
"X-Fern-Language": "Python",
1919
"X-Fern-SDK-Name": "zep-cloud",
20-
"X-Fern-SDK-Version": "2.12.2",
20+
"X-Fern-SDK-Version": "2.12.3",
2121
}
2222
headers["Authorization"] = f"Api-Key {self.api_key}"
2323
return headers

src/zep_cloud/graph/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def add(
144144
request_options: typing.Optional[RequestOptions] = None
145145
) -> Episode:
146146
"""
147-
Add data to the graph. Note: each subscription tier has different limits on the amount of data that can be added to the graph please refer to the pricing page for more information.
147+
Add data to the graph.
148148
149149
Parameters
150150
----------
@@ -219,7 +219,7 @@ def add_batch(
219219
request_options: typing.Optional[RequestOptions] = None
220220
) -> typing.List[Episode]:
221221
"""
222-
Add data to the graph in batch mode (each episode processed concurrently). Note: each subscription tier has different limits on the amount of data that can be added to the graph please refer to the pricing page for more information.
222+
Add data to the graph in batch mode, processing episodes concurrently. Use only for data that is insensitive to processing order.
223223
224224
Parameters
225225
----------
@@ -644,7 +644,7 @@ async def add(
644644
request_options: typing.Optional[RequestOptions] = None
645645
) -> Episode:
646646
"""
647-
Add data to the graph. Note: each subscription tier has different limits on the amount of data that can be added to the graph please refer to the pricing page for more information.
647+
Add data to the graph.
648648
649649
Parameters
650650
----------
@@ -727,7 +727,7 @@ async def add_batch(
727727
request_options: typing.Optional[RequestOptions] = None
728728
) -> typing.List[Episode]:
729729
"""
730-
Add data to the graph in batch mode (each episode processed concurrently). Note: each subscription tier has different limits on the amount of data that can be added to the graph please refer to the pricing page for more information.
730+
Add data to the graph in batch mode, processing episodes concurrently. Use only for data that is insensitive to processing order.
731731
732732
Parameters
733733
----------

0 commit comments

Comments
 (0)