Skip to content

Commit 2d4936f

Browse files
committed
Add support for vector lookup
Use indexing
2 parents b0325a0 + 3581dce commit 2d4936f

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8+
.langgraph_api
89

910
# Distribution / packaging
1011
.Python

langgraph.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
},
66
"env": ".env",
77
"python_version": "3.11",
8-
"dependencies": ["."]
8+
"dependencies": ["."],
9+
"store": {
10+
"index": {
11+
"dims": 1536,
12+
"embed": "openai:text-embedding-3-small"
13+
}
14+
}
915
}

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies = [
1313
# Optional (for selecting different models)
1414
"langchain-openai>=0.2.1",
1515
"langchain-anthropic>=0.2.1",
16-
"langchain>=0.3.1",
16+
"langchain>=0.3.8",
1717
"langchain-core>=0.3.8",
1818
"python-dotenv>=1.0.1",
1919
"langgraph-sdk>=0.1.32",

src/memory_agent/graph.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ async def call_model(state: State, config: RunnableConfig, *, store: BaseStore)
2424

2525
# Retrieve the most recent memories for context
2626
memories = await store.asearch(
27-
("memories", configurable.user_id), limit=10
27+
("memories", configurable.user_id),
28+
query=str([m.content for m in state.messages[-3:]]),
29+
limit=10,
2830
)
2931

3032
# Format memories for inclusion in the prompt
31-
formatted = "\n".join(f"[{mem.key}]: {mem.value}" for mem in memories)
33+
formatted = "\n".join(f"[{mem.key}]: {mem.value} (similarity: {mem.score})" for mem in memories)
3234
if formatted:
3335
formatted = f"""
3436
<memories>

src/memory_agent/tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ async def upsert_memory(
4040
key=str(mem_id),
4141
value={"content": content, "context": context},
4242
)
43-
return f"Stored memory {memory_id}"
43+
return f"Stored memory {mem_id}"

0 commit comments

Comments
 (0)