Loading...
Loading...
Configure Lakebase for agent memory storage. Use when: (1) Adding memory capabilities to the agent, (2) 'Failed to connect to Lakebase' errors, (3) Permission errors on checkpoint/store tables, (4) User says 'lakebase', 'memory setup', or 'add memory'.
npx skill4agent add databricks/app-templates lakebase-setupNote: This template does not include memory by default. Use this skill if you want to add memory capabilities to your agent. For pre-configured memory templates, see:
- Conversation history within a sessionagent-langgraph-short-term-memory - User facts that persist across sessionsagent-langgraph-long-term-memory
AsyncCheckpointSaverAsyncDatabricksStore┌─────────────────────────────────────────────────────────────────────────────┐
│ 1. Add dependency → 2. Get instance → 3. Configure DAB + app.yaml │
│ 4. Configure .env → 5. Initialize tables → 6. Deploy + Run │
└─────────────────────────────────────────────────────────────────────────────┘pyproject.tomldependencies = [
"databricks-langchain[memory]",
# ... other dependencies
]uv syncdatabasedatabricks.ymlresources:
apps:
agent_langgraph:
name: "your-app-name"
source_code_path: ./
resources:
# ... other resources (experiment, UC functions, etc.) ...
# Lakebase instance for long-term memory
- name: 'database'
database:
instance_name: '<your-lakebase-instance-name>'
database_name: 'postgres'
permission: 'CAN_CONNECT_AND_CREATE'instance_name: '<your-lakebase-instance-name>'valueapp.yamldatabaseapp.yamlenv:
# ... other env vars ...
# Lakebase instance name - must match instance_name in databricks.yml database resource
# Note: Use 'value' (not 'valueFrom') because AsyncDatabricksStore needs the instance name,
# not the full connection string that valueFrom would provide
- name: LAKEBASE_INSTANCE_NAME
value: "<your-lakebase-instance-name>"
# Static values for embedding configuration
- name: EMBEDDING_ENDPOINT
value: "databricks-gte-large-en"
- name: EMBEDDING_DIMS
value: "1024"LAKEBASE_INSTANCE_NAMEinstance_namedatabricks.ymldatabaseapp.yamlvalueFrom.env# Lakebase configuration for long-term memory
LAKEBASE_INSTANCE_NAME=<your-instance-name>
EMBEDDING_ENDPOINT=databricks-gte-large-en
EMBEDDING_DIMS=1024embedding_dims| Endpoint | Dimensions |
|---|---|
| 1024 |
| 1024 |
Note:is only for local development. When deployed, the app gets.envfrom theLAKEBASE_INSTANCE_NAMEreference invalueFrom.app.yaml
AsyncDatabricksStore# Run this script locally BEFORE first deployment
import asyncio
from databricks_langchain import AsyncDatabricksStore
async def setup_store():
async with AsyncDatabricksStore(
instance_name="<your-instance-name>",
embedding_endpoint="databricks-gte-large-en",
embedding_dims=1024,
) as store:
print("Setting up store tables...")
await store.setup() # Creates required tables
print("Store tables created!")
# Verify with a test write/read
await store.aput(("test", "init"), "test_key", {"value": "test_value"})
results = await store.asearch(("test", "init"), query="test", limit=1)
print(f"Test successful: {results}")
asyncio.run(setup_store())uv run python -c "$(cat <<'EOF'
import asyncio
from databricks_langchain import AsyncDatabricksStore
async def setup():
async with AsyncDatabricksStore(
instance_name="<your-instance-name>",
embedding_endpoint="databricks-gte-large-en",
embedding_dims=1024,
) as store:
await store.setup()
print("Tables created!")
asyncio.run(setup())
EOF
)"publicstorestore_vectorsstore_migrationsvector_migrationsdeployrun# Deploy resources and upload files
databricks bundle deploy
# Start/restart the app with new code (REQUIRED!)
databricks bundle run agent_langgraphNote:only uploads files and configures resources.bundle deployis required to actually start the app with the new code.bundle run
bundle:
name: agent_langgraph
resources:
experiments:
agent_langgraph_experiment:
name: /Users/${workspace.current_user.userName}/${bundle.name}-${bundle.target}
apps:
agent_langgraph:
name: "my-agent-app"
description: "Agent with long-term memory"
source_code_path: ./
resources:
- name: 'experiment'
experiment:
experiment_id: "${resources.experiments.agent_langgraph_experiment.id}"
permission: 'CAN_MANAGE'
# Lakebase instance for long-term memory
- name: 'database'
database:
instance_name: '<your-lakebase-instance-name>'
database_name: 'postgres'
permission: 'CAN_CONNECT_AND_CREATE'
targets:
dev:
mode: development
default: truecommand: ["uv", "run", "start-app"]
env:
- name: MLFLOW_TRACKING_URI
value: "databricks"
- name: MLFLOW_REGISTRY_URI
value: "databricks-uc"
- name: API_PROXY
value: "http://localhost:8000/invocations"
- name: CHAT_APP_PORT
value: "3000"
- name: CHAT_PROXY_TIMEOUT_SECONDS
value: "300"
# Reference experiment resource from databricks.yml
- name: MLFLOW_EXPERIMENT_ID
valueFrom: "experiment"
# Lakebase instance name (must match instance_name in databricks.yml)
- name: LAKEBASE_INSTANCE_NAME
value: "<your-lakebase-instance-name>"
# Embedding configuration
- name: EMBEDDING_ENDPOINT
value: "databricks-gte-large-en"
- name: EMBEDDING_DIMS
value: "1024"| Issue | Cause | Solution |
|---|---|---|
| "embedding_dims is required when embedding_endpoint is specified" | Missing | Add |
| "relation 'store' does not exist" | Tables not initialized | Run |
| "Unable to resolve Lakebase instance 'None'" | Missing env var in deployed app | Add |
| "Unable to resolve Lakebase instance '...database.cloud.databricks.com'" | Used valueFrom instead of value | Use |
| "permission denied for table store" | Missing grants | The |
| "Failed to connect to Lakebase" | Wrong instance name | Verify instance name in databricks.yml and .env |
| Connection pool errors on exit | Python cleanup race | Ignore |
| App not updated after deploy | Forgot to run bundle | Run |
| valueFrom not resolving | Resource name mismatch | Ensure |
databasefrom databricks_ai_bridge.lakebase import LakebaseClient, SchemaPrivilege, TablePrivilege
client = LakebaseClient(instance_name="...")
# Create role (must do first)
client.create_role(identity_name, "SERVICE_PRINCIPAL")
# Grant schema (note: schemas is a list, grantee not role)
client.grant_schema(
grantee="...",
schemas=["public"],
privileges=[SchemaPrivilege.USAGE, SchemaPrivilege.CREATE],
)
# Grant tables (note: tables includes schema prefix)
client.grant_table(
grantee="...",
tables=["public.store"],
privileges=[TablePrivilege.SELECT, TablePrivilege.INSERT, ...],
)
# Execute raw SQL
client.execute("SELECT * FROM pg_tables WHERE schemaname = 'public'")| Field | Format | Example |
|---|---|---|
| Numeric ID | |
| UUID | |
| String name | |
databricks apps get <app-name> --output json | jq '{
id: .service_principal_id,
client_id: .service_principal_client_id,
name: .service_principal_name
}'LakebaseClient.create_role()service_principal_client_idservice_principal_nameservice_principal_client_id