Skip to content

Commit

Permalink
Merge pull request #8 from langchain-ai/wfh/vector_lookup
Browse files Browse the repository at this point in the history
Support vector lookup
  • Loading branch information
hinthornw authored Dec 3, 2024
2 parents 4f30032 + b9a922a commit 4a390a5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ __pycache__/

# C extensions
*.so
.langgraph_api
.vscode

# Distribution / packaging
.Python
Expand Down
8 changes: 7 additions & 1 deletion langgraph.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
},
"env": ".env",
"python_version": "3.11",
"dependencies": ["."]
"dependencies": ["."],
"store": {
"index": {
"dims": 1536,
"embed": "openai:text-embedding-3-small"
}
}
}
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down
3 changes: 2 additions & 1 deletion src/chatbot/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/memory_graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4a390a5

Please sign in to comment.