Skip to content

Commit 7cd2265

Browse files
Bin1783WillemJiangCopilot
authored
append messages to chat_streams table (bytedance#816)
* feat: Implement DeerFlow API server with chat streaming, Langgraph orchestration, and various content generation capabilities. * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * - Use MongoDB `$push` with `$each` to append new messages to existing threads - Use PostgreSQL jsonb concatenation operator to merge messages instead of overwriting - Update comments to reflect append behavior in both database implementations --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6ec170c commit 7cd2265

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/graph/checkpoint.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,13 @@ def _persist_to_mongodb(self, thread_id: str, messages: List[str]) -> bool:
248248
current_timestamp = datetime.now()
249249

250250
if existing_document:
251-
# Update existing conversation with new messages
251+
# Append new messages to existing conversation
252252
update_result = collection.update_one(
253253
{"thread_id": thread_id},
254-
{"$set": {"messages": messages, "ts": current_timestamp}},
254+
{
255+
"$push": {"messages": {"$each": messages}},
256+
"$set": {"ts": current_timestamp}
257+
},
255258
)
256259
self.logger.info(
257260
f"Updated conversation for thread {thread_id}: "
@@ -290,11 +293,11 @@ def _persist_to_postgresql(self, thread_id: str, messages: List[str]) -> bool:
290293
messages_json = json.dumps(messages)
291294

292295
if existing_record:
293-
# Update existing conversation with new messages
296+
# Append new messages to existing conversation
294297
cursor.execute(
295298
"""
296-
UPDATE chat_streams
297-
SET messages = %s, ts = %s
299+
UPDATE chat_streams
300+
SET messages = messages || %s::jsonb, ts = %s
298301
WHERE thread_id = %s
299302
""",
300303
(messages_json, current_timestamp, thread_id),

0 commit comments

Comments
 (0)