-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Firestore memory #1975
base: main
Are you sure you want to change the base?
Firestore memory #1975
Conversation
Can you please add a corresponding cookbook and add the steps to setup firestore and get the required env variables at the top of the cookbook? |
Hi @manthanguptaa I've added the cookbook |
from typing import Optional, List | ||
from datetime import datetime, timezone | ||
|
||
try: | ||
from google.cloud import firestore | ||
from google.cloud.firestore import Client | ||
from google.cloud.firestore import CollectionReference | ||
from google.cloud.firestore_v1.base_query import FieldFilter, BaseQuery | ||
import google.auth | ||
except ImportError: | ||
raise ImportError( | ||
"`firestore` not installed. Please install it with `pip install google-cloud-firestore`" | ||
) | ||
|
||
from agno.memory.db import MemoryDb | ||
from agno.memory.row import MemoryRow | ||
from agno.utils.log import logger |
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.
from typing import Optional, List | |
from datetime import datetime, timezone | |
try: | |
from google.cloud import firestore | |
from google.cloud.firestore import Client | |
from google.cloud.firestore import CollectionReference | |
from google.cloud.firestore_v1.base_query import FieldFilter, BaseQuery | |
import google.auth | |
except ImportError: | |
raise ImportError( | |
"`firestore` not installed. Please install it with `pip install google-cloud-firestore`" | |
) | |
from agno.memory.db import MemoryDb | |
from agno.memory.row import MemoryRow | |
from agno.utils.log import logger | |
from typing import Optional, List | |
from datetime import datetime, timezone | |
from agno.memory.db import MemoryDb | |
from agno.memory.row import MemoryRow | |
from agno.utils.log import logger | |
try: | |
from google.cloud import firestore | |
from google.cloud.firestore import Client | |
from google.cloud.firestore import CollectionReference | |
from google.cloud.firestore_v1.base_query import FieldFilter, BaseQuery | |
import google.auth | |
except ImportError: | |
raise ImportError( | |
"`firestore` not installed. Please install it with `pip install google-cloud-firestore`" | |
) | |
def __init__( | ||
self, | ||
collection_name: str = "memory", | ||
db_name: Optional[str] = "(default)", |
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.
db_name: Optional[str] = "(default)", | |
db_name: Optional[str] = "agno", |
def create(self) -> None: | ||
"""Create the collection index | ||
Avoiding index creation by using a user/memory model | ||
|
||
Returns: | ||
None | ||
""" | ||
try: | ||
logger.info(f"Mocked call to create index for '{self.collection_name}'") | ||
except Exception as e: | ||
logger.error(f"Error creating collection: {e}") | ||
raise |
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 noticed this doesn’t seem to be doing anything. Was that intentional? Just wanted to check.
""" | ||
This recipe shows how to store agent sessions in a MongoDB database. | ||
Steps: | ||
1. Run: `pip install openai google-cloud-firestore agno` to install dependencies | ||
2. Make sure your gcloud project is set up and you have the necessary permissions to access Firestore | ||
3. Run: `python cookbook/memory/09_persistent_memory_firestore.py` to run the agent | ||
""" | ||
|
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 please also mention steps on how to set up gcloud locally and set up the project?
def drop_table(self) -> None: | ||
"""Drop the collection | ||
Returns: | ||
None | ||
""" | ||
try: | ||
# todo https://firebase.google.com/docs/firestore/solutions/delete-collections | ||
# no easy way | ||
logger.info("call to drop table") | ||
except Exception as e: | ||
logger.error(f"Error dropping collection: {e}") |
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.
we will need to implement this as it is an important function
def clear(self) -> bool: | ||
"""Clear the collection | ||
Returns: | ||
bool: True if the collection was cleared, False otherwise | ||
""" | ||
try: | ||
# todo https://firebase.google.com/docs/firestore/solutions/delete-collections | ||
logger.info("call to clear the collection") | ||
return True | ||
except Exception as e: | ||
logger.error(f"Error clearing collection: {e}") | ||
return False |
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.
Similarly here
Description
Adds firestore memory to solve #1974
Fixes # (issue)
[Feature Request] firestore agent memory #1974
Type of change
Checklist
./scripts/format.sh
and./scripts/validate.sh
to ensure code is formatted and linted.Additional Notes
firestore works best without having to create indexes. The data model collection_name/user_id/memories allows for selecting all memories and using an orderby without having to create a composite index which is a bit tricky in firestore (requires async calls, no callback when completed, not ready immediately).