diff --git a/.gitignore b/.gitignore index b8af3ff..c00e3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ __pycache__/ # C extensions *.so +.langgraph_api +.vscode # Distribution / packaging .Python diff --git a/langgraph.json b/langgraph.json index ee9be20..b96e90e 100644 --- a/langgraph.json +++ b/langgraph.json @@ -6,5 +6,11 @@ }, "env": ".env", "python_version": "3.11", - "dependencies": ["."] + "dependencies": ["."], + "store": { + "index": { + "dims": 1536, + "embed": "openai:text-embedding-3-small" + } + } } diff --git a/pyproject.toml b/pyproject.toml index e22c337..6fb4418 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,13 +9,14 @@ readme = "README.md" license = { text = "MIT" } requires-python = ">=3.9" dependencies = [ - "langgraph>=0.2.32,<0.3.0", + "langgraph>=0.2.53,<0.3.0", + "langgraph-checkpoint>=2.0.8", # Optional (for selecting different models) "langchain-openai>=0.2.1", "langchain-anthropic>=0.2.1", - "langchain>=0.3.1", + "langchain>=0.3.8", "python-dotenv>=1.0.1", - "langgraph-sdk>=0.1.32", + "langgraph-sdk>=0.1.40", "trustcall>=0.0.21", ] diff --git a/src/chatbot/graph.py b/src/chatbot/graph.py index ba81690..9612faf 100644 --- a/src/chatbot/graph.py +++ b/src/chatbot/graph.py @@ -29,7 +29,8 @@ async def bot( namespace = (configurable.user_id,) # This lists ALL user memories in the provided namespace (up to the `limit`) # you can also filter by content. - items = await store.asearch(namespace) + query = "\n".join(str(message.content) for message in state.messages) + items = await store.asearch(namespace, query=query, limit=10) model = init_model(configurable.model) prompt = configurable.system_prompt.format( diff --git a/src/memory_graph/graph.py b/src/memory_graph/graph.py index 09c1da0..76b6f43 100644 --- a/src/memory_graph/graph.py +++ b/src/memory_graph/graph.py @@ -80,7 +80,8 @@ async def handle_insertion_memory( namespace = (configurable.user_id, "events", state.function_name) # Fetch existing memories from the store (5 most recent ones) for the this (insert) memory schema - existing_items = await store.asearch(namespace, limit=5) + query = "\n".join(str(message.content) for message in state.messages)[-3000:] + existing_items = await store.asearch(namespace, query=query, limit=5) # Get the configuration for this memory schema (identified by function_name) memory_config = next(