Skip to content

Commit

Permalink
Add support for vector lookup
Browse files Browse the repository at this point in the history
Use indexing
  • Loading branch information
hinthornw committed Dec 4, 2024
2 parents b0325a0 + 3581dce commit 2d4936f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ __pycache__/

# C extensions
*.so
.langgraph_api

# 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 @@ -5,5 +5,11 @@
},
"env": ".env",
"python_version": "3.11",
"dependencies": ["."]
"dependencies": ["."],
"store": {
"index": {
"dims": 1536,
"embed": "openai:text-embedding-3-small"
}
}
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
# Optional (for selecting different models)
"langchain-openai>=0.2.1",
"langchain-anthropic>=0.2.1",
"langchain>=0.3.1",
"langchain>=0.3.8",
"langchain-core>=0.3.8",
"python-dotenv>=1.0.1",
"langgraph-sdk>=0.1.32",
Expand Down
6 changes: 4 additions & 2 deletions src/memory_agent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ async def call_model(state: State, config: RunnableConfig, *, store: BaseStore)

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

# Format memories for inclusion in the prompt
formatted = "\n".join(f"[{mem.key}]: {mem.value}" for mem in memories)
formatted = "\n".join(f"[{mem.key}]: {mem.value} (similarity: {mem.score})" for mem in memories)
if formatted:
formatted = f"""
<memories>
Expand Down
2 changes: 1 addition & 1 deletion src/memory_agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ async def upsert_memory(
key=str(mem_id),
value={"content": content, "context": context},
)
return f"Stored memory {memory_id}"
return f"Stored memory {mem_id}"

0 comments on commit 2d4936f

Please sign in to comment.