diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 3167d5520..29d58b077 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -225,6 +225,7 @@ nav: - cloud/deployment/setup.md - cloud/deployment/setup_pyproject.md - cloud/deployment/setup_javascript.md + - cloud/deployment/semantic_search.md - cloud/deployment/custom_docker.md - cloud/deployment/test_locally.md - cloud/deployment/graph_rebuild.md diff --git a/libs/checkpoint-postgres/langgraph/store/postgres/aio.py b/libs/checkpoint-postgres/langgraph/store/postgres/aio.py index 9be44ded6..cbdd4cfc1 100644 --- a/libs/checkpoint-postgres/langgraph/store/postgres/aio.py +++ b/libs/checkpoint-postgres/langgraph/store/postgres/aio.py @@ -72,6 +72,8 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con # Store documents await store.aput(("docs",), "doc1", {"text": "Python tutorial"}) await store.aput(("docs",), "doc2", {"text": "TypeScript guide"}) + # Don't index the following + await store.aput(("docs",), "doc3", {"text": "Other guide"}, index=False) # Search by similarity results = await store.asearch(("docs",), query="python programming") diff --git a/libs/checkpoint-postgres/langgraph/store/postgres/base.py b/libs/checkpoint-postgres/langgraph/store/postgres/base.py index e12a59667..d0fd58da5 100644 --- a/libs/checkpoint-postgres/langgraph/store/postgres/base.py +++ b/libs/checkpoint-postgres/langgraph/store/postgres/base.py @@ -569,6 +569,7 @@ class PostgresStore(BaseStore, BasePostgresStore[_pg_internal.Conn]): # Store documents store.put(("docs",), "doc1", {"text": "Python tutorial"}) store.put(("docs",), "doc2", {"text": "TypeScript guide"}) + store.put(("docs",), "doc2", {"text": "Other guide"}, index=False) # don't index # Search by similarity results = store.search(("docs",), query="python programming") diff --git a/libs/checkpoint/langgraph/store/base/__init__.py b/libs/checkpoint/langgraph/store/base/__init__.py index 3f36b7f16..6406527d3 100644 --- a/libs/checkpoint/langgraph/store/base/__init__.py +++ b/libs/checkpoint/langgraph/store/base/__init__.py @@ -557,10 +557,15 @@ class IndexConfig(TypedDict, total=False): """Fields to extract text from for embedding generation. Controls which parts of stored items are embedded for semantic search. Follows JSON path syntax: - - ["$"] (default): Embeds the entire JSON object as one vector - - ["field1", "field2"]: Embeds specific top-level fields - - ["parent.child"]: Embeds nested fields using dot notation - - ["array[*].field"]: Embeds field from each array element separately + + - ["$"]: Embeds the entire JSON object as one vector (default) + - ["field1", "field2"]: Embeds specific top-level fields + - ["parent.child"]: Embeds nested fields using dot notation + - ["array[*].field"]: Embeds field from each array element separately + + Note: + You can always override this behavior when storing an item using the + `index` parameter in the `put` or `aput` operations. ???+ example "Examples" ```python @@ -706,6 +711,8 @@ class BaseStore(ABC): index: Controls how the item's fields are indexed for search: - None (default): Use `fields` you configured when creating the store (if any) + If you do not initialize the store with indexing capabilities, + the `index` parameter will be ignored - False: Disable indexing for this item - list[str]: List of field paths to index, supporting: - Nested fields: "metadata.title" @@ -713,8 +720,9 @@ class BaseStore(ABC): - Specific indices: "authors[0].name" Note: - Indexing capabilities depend on your store implementation. - Some implementations may support only a subset of indexing features. + Indexing support depends on your store implementation. + If you do not initialize the store with indexing capabilities, + the `index` parameter will be ignored. ???+ example "Examples" Store item. Indexing depends on how you configure the store. @@ -890,6 +898,8 @@ class BaseStore(ABC): index: Controls how the item's fields are indexed for search: - None (default): Use `fields` you configured when creating the store (if any) + If you do not initialize the store with indexing capabilities, + the `index` parameter will be ignored - False: Disable indexing for this item - list[str]: List of field paths to index, supporting: - Nested fields: "metadata.title" @@ -897,8 +907,9 @@ class BaseStore(ABC): - Specific indices: "authors[0].name" Note: - Indexing capabilities depend on your store implementation. - Some implementations may support only a subset of indexing features. + Indexing support depends on your store implementation. + If you do not initialize the store with indexing capabilities, + the `index` parameter will be ignored. ???+ example "Examples" Store item. Indexing depends on how you configure the store.