CLI (original) (raw)
Basic Configuration¶
[](#%5F%5Fcodelineno-2-1){ [](#%5F%5Fcodelineno-2-2) "dependencies": ["."], [](#%5F%5Fcodelineno-2-3) "graphs": { [](#%5F%5Fcodelineno-2-4) "chat": "./chat/graph.py:graph" [](#%5F%5Fcodelineno-2-5) } [](#%5F%5Fcodelineno-2-6)}
Adding semantic search to the store¶
All deployments come with a DB-backed BaseStore. Adding an "index" configuration to your langgraph.json
will enable semantic search within the BaseStore of your deployment.
The index.fields
configuration determines which parts of your documents to embed:
- If omitted or set to
["$"]
, the entire document will be embedded - To embed specific fields, use JSON path notation:
["metadata.title", "content.text"]
- Documents missing specified fields will still be stored but won't have embeddings for those fields
- You can still override which fields to embed on a specific item at
put
time using theindex
parameter
[](#%5F%5Fcodelineno-3-1){ [](#%5F%5Fcodelineno-3-2) "dependencies": ["."], [](#%5F%5Fcodelineno-3-3) "graphs": { [](#%5F%5Fcodelineno-3-4) "memory_agent": "./agent/graph.py:graph" [](#%5F%5Fcodelineno-3-5) }, [](#%5F%5Fcodelineno-3-6) "store": { [](#%5F%5Fcodelineno-3-7) "index": { [](#%5F%5Fcodelineno-3-8) "embed": "openai:text-embedding-3-small", [](#%5F%5Fcodelineno-3-9) "dims": 1536, [](#%5F%5Fcodelineno-3-10) "fields": ["$"] [](#%5F%5Fcodelineno-3-11) } [](#%5F%5Fcodelineno-3-12) } [](#%5F%5Fcodelineno-3-13)}
Common model dimensions
openai:text-embedding-3-large
: 3072openai:text-embedding-3-small
: 1536openai:text-embedding-ada-002
: 1536cohere:embed-english-v3.0
: 1024cohere:embed-english-light-v3.0
: 384cohere:embed-multilingual-v3.0
: 1024cohere:embed-multilingual-light-v3.0
: 384
Semantic search with a custom embedding function¶
If you want to use semantic search with a custom embedding function, you can pass a path to a custom embedding function:
[](#%5F%5Fcodelineno-4-1){ [](#%5F%5Fcodelineno-4-2) "dependencies": ["."], [](#%5F%5Fcodelineno-4-3) "graphs": { [](#%5F%5Fcodelineno-4-4) "memory_agent": "./agent/graph.py:graph" [](#%5F%5Fcodelineno-4-5) }, [](#%5F%5Fcodelineno-4-6) "store": { [](#%5F%5Fcodelineno-4-7) "index": { [](#%5F%5Fcodelineno-4-8) "embed": "./embeddings.py:embed_texts", [](#%5F%5Fcodelineno-4-9) "dims": 768, [](#%5F%5Fcodelineno-4-10) "fields": ["text", "summary"] [](#%5F%5Fcodelineno-4-11) } [](#%5F%5Fcodelineno-4-12) } [](#%5F%5Fcodelineno-4-13)}
The embed
field in store configuration can reference a custom function that takes a list of strings and returns a list of embeddings. Example implementation:
[](#%5F%5Fcodelineno-5-1)# embeddings.py [](#%5F%5Fcodelineno-5-2)def embed_texts(texts: list[str]) -> list[list[float]]: [](#%5F%5Fcodelineno-5-3) """Custom embedding function for semantic search.""" [](#%5F%5Fcodelineno-5-4) # Implementation using your preferred embedding model [](#%5F%5Fcodelineno-5-5) return [[0.1, 0.2, ...] for _ in texts] # dims-dimensional vectors
Adding custom authentication¶
[](#%5F%5Fcodelineno-6-1){ [](#%5F%5Fcodelineno-6-2) "dependencies": ["."], [](#%5F%5Fcodelineno-6-3) "graphs": { [](#%5F%5Fcodelineno-6-4) "chat": "./chat/graph.py:graph" [](#%5F%5Fcodelineno-6-5) }, [](#%5F%5Fcodelineno-6-6) "auth": { [](#%5F%5Fcodelineno-6-7) "path": "./auth.py:auth", [](#%5F%5Fcodelineno-6-8) "openapi": { [](#%5F%5Fcodelineno-6-9) "securitySchemes": { [](#%5F%5Fcodelineno-6-10) "apiKeyAuth": { [](#%5F%5Fcodelineno-6-11) "type": "apiKey", [](#%5F%5Fcodelineno-6-12) "in": "header", [](#%5F%5Fcodelineno-6-13) "name": "X-API-Key" [](#%5F%5Fcodelineno-6-14) } [](#%5F%5Fcodelineno-6-15) }, [](#%5F%5Fcodelineno-6-16) "security": [{ "apiKeyAuth": [] }] [](#%5F%5Fcodelineno-6-17) }, [](#%5F%5Fcodelineno-6-18) "disable_studio_auth": false [](#%5F%5Fcodelineno-6-19) } [](#%5F%5Fcodelineno-6-20)}
See the authentication conceptual guide for details, and the setting up custom authentication guide for a practical walk through of the process.
Configuring Store Item Time-to-Live (TTL)¶
You can configure default data expiration for items/memories in the BaseStore using the store.ttl
key. This determines how long items are retained after they are last accessed (with reads potentially refreshing the timer based on refresh_on_read
). Note that these defaults can be overwritten on a per-call basis by modifying the corresponding arguments in get
, search
, etc.
The ttl
configuration is an object containing optional fields:
refresh_on_read
: Iftrue
(the default), accessing an item viaget
orsearch
resets its expiration timer. Set tofalse
to only refresh TTL on writes (put
).default_ttl
: The default lifespan of an item in minutes. If not set, items do not expire by default.sweep_interval_minutes
: How frequently (in minutes) the system should run a background process to delete expired items. If not set, sweeping does not occur automatically.
Here is an example enabling a 7-day TTL (10080 minutes), refreshing on reads, and sweeping every hour:
[](#%5F%5Fcodelineno-7-1){ [](#%5F%5Fcodelineno-7-2) "dependencies": ["."], [](#%5F%5Fcodelineno-7-3) "graphs": { [](#%5F%5Fcodelineno-7-4) "memory_agent": "./agent/graph.py:graph" [](#%5F%5Fcodelineno-7-5) }, [](#%5F%5Fcodelineno-7-6) "store": { [](#%5F%5Fcodelineno-7-7) "ttl": { [](#%5F%5Fcodelineno-7-8) "refresh_on_read": true, [](#%5F%5Fcodelineno-7-9) "sweep_interval_minutes": 60, [](#%5F%5Fcodelineno-7-10) "default_ttl": 10080 [](#%5F%5Fcodelineno-7-11) } [](#%5F%5Fcodelineno-7-12) } [](#%5F%5Fcodelineno-7-13)}
Configuring Checkpoint Time-to-Live (TTL)¶
You can configure the time-to-live (TTL) for checkpoints using the checkpointer
key. This determines how long checkpoint data is retained before being automatically handled according to the specified strategy (e.g., deletion). The ttl
configuration is an object containing:
strategy
: The action to take on expired checkpoints (currently"delete"
is the only accepted option).sweep_interval_minutes
: How frequently (in minutes) the system checks for expired checkpoints.default_ttl
: The default lifespan of a checkpoint in minutes.
Here's an example setting a default TTL of 30 days (43200 minutes):
[](#%5F%5Fcodelineno-8-1){ [](#%5F%5Fcodelineno-8-2) "dependencies": ["."], [](#%5F%5Fcodelineno-8-3) "graphs": { [](#%5F%5Fcodelineno-8-4) "chat": "./chat/graph.py:graph" [](#%5F%5Fcodelineno-8-5) }, [](#%5F%5Fcodelineno-8-6) "checkpointer": { [](#%5F%5Fcodelineno-8-7) "ttl": { [](#%5F%5Fcodelineno-8-8) "strategy": "delete", [](#%5F%5Fcodelineno-8-9) "sweep_interval_minutes": 10, [](#%5F%5Fcodelineno-8-10) "default_ttl": 43200 [](#%5F%5Fcodelineno-8-11) } [](#%5F%5Fcodelineno-8-12) } [](#%5F%5Fcodelineno-8-13)}
In this example, checkpoints older than 30 days will be deleted, and the check runs every 10 minutes.
Basic Configuration¶
[](#%5F%5Fcodelineno-9-1){ [](#%5F%5Fcodelineno-9-2) "graphs": { [](#%5F%5Fcodelineno-9-3) "chat": "./src/graph.ts:graph" [](#%5F%5Fcodelineno-9-4) } [](#%5F%5Fcodelineno-9-5)}