Skip to content

Conversation

bashiryounis
Copy link
Contributor

Add ZepMemory Integration for LlamaIndex

Overview

This PR introduces a ZepMemory class that provides integration between LlamaIndex and Zep, allowing for persistent memory, context enrichment, and retrieval capabilities in LlamaIndex applications.

Features

  • Bidirectional sync between LlamaIndex's ChatMemoryBuffer and Zep's memory store
  • Support for session-based memory management
  • Context enrichment with facts, summaries, and relevant information from previous sessions
  • Memory search capabilities across sessions for user-specific context
  • Message truncation to prevent oversized payloads
  • Graceful error handling for resilient operation

Implementation Details

  • Extends LlamaIndex's BaseMemory class
  • Handles message format conversion between LlamaIndex and Zep
  • Preserves metadata across systems
  • Supports system, user, assistant, and tool message roles
  • Implements memory lifecycle methods (get, put, set, reset, search)

Dependencies

  • Requires zep-python client library

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 20, 2025
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to put this in the mem0 folder? Normally this would be its own integration right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. You’re absolutely right—it should be its own integration. I apologize for the oversight in placing it within the mem0 folder. I'll make the necessary adjustments promptly.

user_id: Optional[str] = None,
memory_key: str = "chat_history",
max_message_length: int = 2500,
**kwargs,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for kwargs if we aren't using them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I'll remove **kwargs from the signature to simplify the code. Thanks for the suggestion!

memory_key=memory_key,
max_message_length=max_message_length,
)
self._client = zep_client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does zep have an async client? There are a few async methods in the base class that would be nice to implement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated the ZepMemory implementation to include full asynchronous support. The new code now implements async versions for all key operations (e.g. _async_sync_from_zep, aget, aput, aset, areset, and asearch). When using an AsyncZep client with the is_async flag set to True, the memory will use these async methods; otherwise, it falls back to the synchronous methods.

Let me know if you have any further suggestions!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logan-markewich could you please let me know if you have any further suggestions

@logan-markewich
Copy link
Collaborator

logan-markewich commented Apr 9, 2025

To add an integration, you'll need more than a single file -- check out other integrations for examples, but you'll need a README and a pyproject.toml at a minimum

Tests would also be nice

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 14, 2025
@bashiryounis
Copy link
Contributor Author

  • Added a README and a notebook to demonstrate usage and integration with the Zep memory server for testing and exploration.

  • Added tests for both sync and async functionality.

  • Added a pyproject.toml file for project configuration .

Feel free to check it out — I’d love to hear your thoughts and feedback!

Thanks! 🙌

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

This PR is stale because it has been open 50 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Sep 17, 2025
@bashiryounis
Copy link
Contributor Author

bashiryounis commented Sep 21, 2025

Hi @logan-markewich,
Thanks again for your feedback earlier 🙌
Please let me know if there’s anything needed to finalize this contribution.

Appreciate your time and guidance!

Thanks,

@github-actions github-actions bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants