-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[New Example] Long Term Memory for Gemini #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Note Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported. |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
/gemini review |
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
lucifertrj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need it to be in ipynb or should I replace it with py for Gemini code assistant to perform the review.
|
Hi @lucifertrj, thanks for the contribution! Please keep the example as a Interactive Python Notebook (.ipynb). Notebooks are the standard format for examples in this cookbook. It looks like the notebook file isn't rendering correctly on GitHub due to a metadata issue.
Could you please try clearing all the cell outputs in your notebook and then pushing the updated file to this PR? That should resolve the rendering issue. If you're still having trouble, feel free to share a Colab Gist so I can review your work in the meantime. |
|
sure will modify |
|
Hey @chunduriv I have removed the cell outputs. you can view the notebook here: https://github.com/lucifertrj/cookbook/blob/longtermmemory/examples/Long_Term_Memory.ipynb |
|
For the GitHub gist, you can refer to this: https://colab.research.google.com/gist/lucifertrj/91c7fc265a6d40733c7a99bcf9aaa31d/long_term_memory.ipynb |
|
@Giom-V and @chunduriv any updates? I have formatted the notebook -nbfmt. |
| @@ -0,0 +1,465 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -0,0 +1,465 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use GEMINI_API_KEY instead? We're going to migrate to this new naming soon.
Reply via ReviewNB
| @@ -0,0 +1,465 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will switch to gemini embedding
| @@ -0,0 +1,465 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear to me from the code samples what was saved to memory (all the conversation?). Can you add more explanations?
Reply via ReviewNB
| @@ -0,0 +1,465 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be great to explain what's happening here. Is it searching in the memory?
Reply via ReviewNB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I will add the information with one flowchart
| @@ -0,0 +1,465 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you save the outputs in the notebook so one can see what it does without running it
Reply via ReviewNB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually It was present, previously it was mentioned to clear the output cells, so I had removed.
| @@ -0,0 +1,465 @@ | |||
| { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you indent the text like this?
SYSTEM_PROMPT = """ You are an expert executive assistant who thinks carefully before responding, adapting to the poliet communication style based on the previous user's established PREFERENCES and the complexity of their query. Maintain a polished, professional tone that is warm yet efficient—concise for simple questions, moderate for complex topics, and comprehensive for open-ended discussions. Act as a trusted advisor who doesn't just answer questions but adds value through insights, anticipates needs, and prioritizes what matters most while respecting the user's time with clear, actionable responses. """
Reply via ReviewNB
|
@lucifertrj I left you some comments. Basically add more explanations about what's happening. |
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new example notebook demonstrating long-term memory for Gemini using Mem0.AI, Qdrant, and FastEmbed. The example is a valuable addition, showcasing a practical use case for recommendation systems. However, the notebook has several areas that need improvement to align with the repository's style guide. Key issues include incorrect markdown formatting (title, headings, Colab badge URL), use of !pip instead of %pip, hardcoded model names instead of using Colab forms, and formatting issues like line length and inconsistent code style. Additionally, the notebook appears to have not been fully run and formatted before submission, as indicated by populated execution_count fields and missing cell outputs. Finally, this new notebook needs to be added to the examples/README.md file.
| "source": [ | ||
| "## Long Memory Layer using - Mem0, Gemini and Qdrant\n", | ||
| "\n", | ||
| "<a target=\"_blank\" href=\"https://colab.research.google.com/drive/13PYVsCenlKOI2iUnPE0A_LcfGDElOWTR?usp=sharing\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" height=30/></a>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL for the 'Open in Colab' badge is incorrect. It should point to the notebook's location within the GitHub repository, not a Google Drive link, to allow users to open it directly.1
| "<a target=\"_blank\" href=\"https://colab.research.google.com/drive/13PYVsCenlKOI2iUnPE0A_LcfGDElOWTR?usp=sharing\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" height=30/></a>" | |
| "<a target=\"_blank\" href=\"https://colab.research.google.com/github/google-gemini/cookbook/blob/main/examples/Long_Term_Memory.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" height=30/></a>" |
Style Guide References
Footnotes
-
The style guide provides a specific format for the 'Open in Colab' badge URL, which should point to the notebook on GitHub. ↩
examples/Long_Term_Memory.ipynb
Outdated
| "id": "4L89T6n6qibs" | ||
| }, | ||
| "source": [ | ||
| "## Long Memory Layer using - Mem0, Gemini and Qdrant\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples/Long_Term_Memory.ipynb
Outdated
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The execution_count for this cell is 1, and for many others it is not null. This indicates that the notebook formatting script has not been run. Please run the formatter on the notebook before submitting to clear execution counts and ensure consistent formatting.1
Style Guide References
Footnotes
-
If the
execution_counthas changed to something other thannull, it usually indicates that the formatting script has not been run. A warning should be raised. ↩
examples/Long_Term_Memory.ipynb
Outdated
| "!pip install agno mem0ai google-genai\n", | ||
| "!pip install langchain langchain-community fastembed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style guide requires using %pip instead of !pip for installations. It's also recommended to combine installations into a single command and use the -U -q flags for google-genai as specified in the guide.12
| "!pip install agno mem0ai google-genai\n", | |
| "!pip install langchain langchain-community fastembed" | |
| "%pip install -U -q agno mem0ai 'google-genai>=1.0.0' langchain langchain-community fastembed" |
Style Guide References
Footnotes
examples/Long_Term_Memory.ipynb
Outdated
| "id": "3FSrgmEPuC4R" | ||
| }, | ||
| "source": [ | ||
| "### Define the Memory Configuration\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples/Long_Term_Memory.ipynb
Outdated
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "result1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cell is expected to display the content of result1, but its output is missing. To improve readability, notebooks should be saved with their outputs so users can see the results without running the code themselves.1 Please run the notebook to completion and save it with the outputs included. This also applies to other cells where output is expected but missing (e.g., lines 298, 351, 449).
Style Guide References
Footnotes
-
Ideally we want the ouputs to be saved in the notebooks so that one can see what the code does without runnning it. ↩
examples/Long_Term_Memory.ipynb
Outdated
| "source": [ | ||
| "SYSTEM_PROMPT = \"\"\"\n", | ||
| "You are an expert executive assistant who thinks carefully before responding,\n", | ||
| "adapting to the poliet communication style based on the previous user's established PREFERENCES and the complexity of their query.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| " USER_PROMPT = f\"\"\"\n", | ||
| " <question>\n", | ||
| " QUESTION: {query}\n", | ||
| " </question>\n", | ||
| "\n", | ||
| " <PREFERENCE>\n", | ||
| " Preference: {context}\n", | ||
| " </PREFERENCE>\n", | ||
| " \"\"\"\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation in this multi-line f-string is inconsistent. Please format it according to the style guide for long strings to improve readability.1
USER_PROMPT = f"""
<question>
QUESTION: {query}
</question>
<PREFERENCE>
Preference: {context}
</PREFERENCE>
"""
Style Guide References
Footnotes
-
Long text variables should use triple double quotes and proper indentation for better readability. ↩
| "\n", | ||
| " # Config the system prompt and make sure to define the input variables inside the USER PROMPT\n", | ||
| " response = llm_client.models.generate_content(\n", | ||
| " model=\"gemini-2.5-pro\",\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The model ID is hardcoded. For better maintainability and ease of use, the style guide recommends using a Colab form selector to choose the model.1 Please define the model in a separate cell using a parameter, for example:
MODEL_ID = "gemini-2.5-pro" # @param ["gemini-2.5-flash", "gemini-2.5-pro"]Then, use this MODEL_ID variable here.
Style Guide References
Footnotes
-
When selecting a model, use a colab selector for easier maintainability. ↩
sure. will make the modifications |
d57677e to
3e1ac56
Compare
|
@Giom-V I have resolved the comments:
|

Uh oh!
There was an error while loading. Please reload this page.