How to perform a fuzzy search across conversations when using LangGraph’s AsyncPostgresSaver as a checkpointer?

Hey everyone,

I’ve been using LangGraph (served through a FastaAPI) for a while to serve my assistant to multiple users, and I think I’m using its abstractions in the right way (but open to roasts). In my implementation to persist chat history I use AsyncPostgresSaver as a checkpointer for my Agent:

graph = workflow.compile(checkpointer=AsyncPostgresSaver(self._pool))

My thread_id is a string composed of the user ID plus the date. That way, when I want to list all conversations for a certain user, I run something like:

SELECT
    thread_id,
    metadata -> 'writes' -> 'Generate Title' ->> 'title' AS conversation_title,
    checkpoint_id
FROM checkpoints
WHERE metadata -> 'writes' -> 'Generate Title' ->> 'title' IS NOT NULL
  AND thread_id LIKE '%%{user_id}%%';

Now i got the thread_id and can display all the messages like this

config: Dict[str, Any] = {"configurable": {"thread_id": thread_id}}
state = await agent.aget_state(config)
messages = state[0]["messages"]
return messages

Note: for me a thread is basically a chat with a title, what you would normally see on the left bar of ChatGPT.

The problem:

Now I want to search inside a conversation.

The issue is that I’m not 100% sure how the messages are actually stored in Postgres. I’d like to run a string search (or fuzzy search) across all messages of a given user, then group the results by conversation and only show conversations that match.

My questions are:

  • Can this be done directly using the AsyncPostgresSaver storage format, or would I need to store the messages in a separate, more search-friendly table?

  • Has anyone implemented something like this with LangGraph?

  • What’s the best approach to avoid loading every conversation into memory just to search?

  • Cause i can see stuff is saved as Binary Data sometimes (which makes sense for documents)? But I cannot believe that the text part of a message is not searchable

Any advice or patterns you’ve found useful would be appreciated!

Hi! We don’t support accessing the checkpoint data in Postgres outside of the utilities the LangGraph library provides you. For your use case, it is best to store the conversation data in a separate schema you’ve designed.