Custom SqliteStore

This commit is contained in:
William Fu-Hinthorn
2025-05-19 15:53:54 -07:00
parent 1721f6adb6
commit c43dcc3c62
3 changed files with 37 additions and 15 deletions
+11 -15
View File
@@ -1,17 +1,13 @@
{
"dockerfile_lines": [],
"graphs": {
"chatbot": "./src/chatbot/graph.py:graph",
"memory_graph": "./src/memory_graph/graph.py:graph"
},
"env": ".env",
"python_version": "3.11",
"dependencies": ["."],
"store": {
"ttl": {"default_ttl": 1, "refresh_on_read": false, "sweep_interval_minutes": 1},
"index": {
"dims": 1536,
"embed": "openai:text-embedding-3-small"
}
}
"dockerfile_lines": [],
"graphs": {
"chatbot": "./src/chatbot/graph.py:graph",
"memory_graph": "./src/memory_graph/graph.py:graph"
},
"env": ".env",
"python_version": "3.11",
"dependencies": ["."],
"store": {
"path": "./src/memory_graph/sqlite_store.py:generate_store"
}
}
+2
View File
@@ -18,6 +18,7 @@ dependencies = [
"python-dotenv>=1.0.1",
"langgraph-sdk>=0.1.40",
"langmem>=0.0.25",
"langgraph-checkpoint-sqlite>=2.0.10",
]
[build-system]
@@ -61,6 +62,7 @@ ignore_errors = true
[dependency-groups]
dev = [
"langgraph-cli[inmem]>=0.2.10",
"langgraph-api>=0.2.29",
"mypy>=1.15.0",
"pytest-asyncio>=0.26.0",
"ruff>=0.11.2",
+24
View File
@@ -0,0 +1,24 @@
import contextlib
from typing import cast
from langchain.embeddings import init_embeddings
from langchain_core.embeddings import Embeddings
from langgraph.store.base import IndexConfig
from langgraph.store.sqlite import AsyncSqliteStore
embeddings = cast(Embeddings, init_embeddings("openai:text-embedding-3-small"))
@contextlib.asynccontextmanager
async def generate_store():
"""Generate a store, to be open for the duration of the server."""
async with AsyncSqliteStore.from_conn_string(
"./custom_store.sql",
index=IndexConfig(
dims=1536,
embed=embeddings,
fields=["$"],
),
) as store:
await store.setup()
yield store