Commit Graph
87 Commits
Author SHA1 Message Date
William FHandGitHub 5fa196ab38 Update docstrings for store classes (#2616) 2024-12-03 19:51:25 -08:00
William FHandGitHub 0361554fcf Bump Checkpoint Postgres (#2601) 2024-12-02 17:56:23 -08:00
4332a9515d Fixup initial provisioning of aio postgres db (#2571) (#2600)
fixes #2570

---------

Co-authored-by: Tai Groot <tai@taigrr.com>
2024-12-03 01:55:26 +00:00
William FHandGitHub 15f0765d60 Add IVFFlat and HNSW support (#2598)
It seems that actually once i moved the operators & other things out,
the query planner does do reasonable things and do sequential scanning
if filtered N < some size but the index otherwise, even with namespace
filtering.
2024-12-02 17:42:29 -08:00
William FHandGitHub 20f091a277 [postgres] Sort Ascending (#2594)
Adds a few of preliminaries:
1. Makes the returned "score" actually the result of the requested
operation (cosine, inner_product, l2)
2. Sorts asc, etc. so that if you were to add an HNSW index (and not
have any WHERE filters), it would be used
3. Drop the inner WHERE statement if no namespace or other filters are
provided. See (2) for why.
I don't yet add an index to the migrations since I think we need to
agree on the right balance to ensure it's actually used in common query
patterns.
2024-12-03 01:08:24 +00:00
Vadym BardaandGitHub 784821705b checkpoint-postgres: pin psycopg >= 3.2.0 (#2580) 2024-11-29 11:30:19 -05:00
William FHandGitHub 12486d977a Update postgres-checkpoint min bounds (#2564) 2024-11-27 22:31:16 -08:00
William FHandGitHub d767af421b feat: Add vector search (#2535)
- Initializing the store with an 'embedding config' -> this contains the
'dims' (used to create the table) and the encoder object (rn langchain
embeddings object, though that is ......)
- Call setup() -> creates the vector table.

Each document has 1 or more vectors associated with it for each json
path in the embedding config.

Would welcome critique and requests! 

Leaving the params as the defaults for pgvector but open to feedback if
you think it's important to be able to more transparently configure that
in setup()

```python
from typing import TypedDict, List, Dict, Any, Optional

from langchain_openai import OpenAIEmbeddings
from langgraph.graph import StateGraph
from langgraph.store.postgres import PostgresStore

emb_config = {
    "dims": 1536,  # OpenAI embedding dimensions
    "embed": OpenAIEmbeddings(model="text-embedding-3-small"),
    "distance_type": "cosine",
}
with PostgresStore.from_conn_string(
    "postgres://postgres:postgres@localhost:5441",
    embedding=emb_config,
) as store:
    store.setup()


# Define the state type for our graph
class State(TypedDict):
    query: str
    results: Optional[List[Dict[str, Any]]]


def put_stuff(state: State) -> State:
    docs = [
        ("doc1", {"text": "red apple in kitchen"}),
        ("doc2", {"text": "blue car in garage"}),
        ("doc3", {"text": "green apple on table"}),
    ]
    for key, value in docs:
        store.put(("docs",), key, value)


def search_stuff(state: State) -> State:
    """Search for documents using vector similarity."""
    results = store.search(("docs",), query=state["query"])

    return {"results": results}


builder = StateGraph(State)
builder.add_node(put_stuff)
builder.add_node(search_stuff)
builder.add_edge("__start__", "put_stuff")
builder.add_edge("put_stuff", "search_stuff")
# Compile
with PostgresStore.from_conn_string(
    "postgres://postgres:postgres@localhost:5441",
    embedding=emb_config,
) as store:
    chain = builder.compile(store=store)

    result = chain.invoke({"query": "sour apple"})

# Print results
for doc in result["results"]:
    print(doc.key)
    print(doc.value)
    print(doc.response_metadata)

```
2024-11-28 04:40:12 +00:00
William FHandGitHub 62a36befd5 Add in-mem vector search (#2547) 2024-11-27 14:53:24 -08:00
William FHandGitHub 8f649abd0a Release PG Checkpointer (#2536) 2024-11-26 01:44:45 +00:00
98935e1ffd fix: Fix race condition in PostgresSaver (#2494)
Signed-off-by: Tyler Ball <tyleraball@gmail.com>
Co-authored-by: Phoenix Logan <plogan@chanzuckerberg.com>
Co-authored-by: Tyler Ball <2481463+tyler-ball@users.noreply.github.com>
2024-11-25 20:19:52 +00:00
Vadym BardaandGitHub 016a9c1936 checkpoint-postgres: release 2.0.3 (#2455) 2024-11-18 16:55:54 -05:00
vbarda f807b73092 use capabilities 2024-11-18 12:15:18 -05:00
vbarda f0505155a2 cache 2024-11-18 11:12:21 -05:00
vbarda 0a5220aa07 code review 2024-11-14 19:06:41 -05:00
vbarda c2052d11c2 checkpoint-postgres: remove pipeline flag in cursor 2024-11-13 21:42:51 -05:00
Nuno Campos 1e3953d1e0 Test order of update application after Send
- updates from inside Send tasks are applied in the order the Sends were created, if when you fan out, and have each task write results to a list with reducer, the final list is in the order you used when triggering
2024-11-01 13:23:10 -07:00
Vadym BardaandGitHub 39d9cdbef0 checkpoint-postgres: release 2.0.2 (#2183) 2024-10-24 17:06:36 -04:00
Vadym BardaandGitHub def3e06b4a move py.typed to submodules for namespace packages (#2177) 2024-10-24 13:43:43 -04:00
Vadym BardaandGitHub 62a5ec509d checkpoint: add DuckDB store (#2154) 2024-10-23 22:20:10 +00:00
Vadym BardaandGitHub d32386f849 checkpoint: add DuckDB checkpointer (#2145) 2024-10-23 21:11:03 +00:00
Nuno Campos cb7b667e6f Update psycopg 2024-10-10 16:09:24 -07:00
William FHandGitHub 254b12a62d Use AsyncBatch for postgres store (#2020) 2024-10-08 06:58:26 +00:00
William FHandGitHub 6c0da426c6 [PostGres Checkpointer] Run CI on PG15 as well (#1953) 2024-10-02 19:16:58 +00:00
William FHandGitHub 5c3ac5d16d Update PG Implementation (#1948) 2024-10-01 13:11:19 -07:00
Vadym BardaandGitHub 4a45f6c99a langgraph, sqlite, postgres: update to use langgraph-checkpoint==2.0.0 (#1946) 2024-10-01 15:28:06 -04:00
William FHandGitHub dd88ac6224 Bump SDK Py (#1935) 2024-10-01 08:17:51 +00:00
William FHandGitHub 29f58fd9e5 Custom loads support in postgres checkpointer (#1930) 2024-09-30 16:42:23 -07:00
William FHandGitHub 97f79fc66b Add Postgres Store Implementation (#1906) 2024-09-30 21:18:58 +00:00
Vadym BardaandGitHub ea0418334b checkpoint-postgres: release 1.0.9 (#1890) 2024-09-27 16:12:06 -04:00
Vadym BardaandGitHub bf19dc7d08 checkpoint-postgres: handle null chars in metadata (#1885) 2024-09-27 16:02:03 +00:00
Vadym BardaandGitHub 659d127d2b checkpoint postgres,sqlite: update langgraph-checkpoint to 1.0.11 (#1815) 2024-09-23 22:09:28 +00:00
Vadym BardaandGitHub 7d513bcde2 checkpoint postgres,sqlite: update langgraph-checkpoint (#1813) 2024-09-23 21:47:26 +00:00
Vadym BardaandGitHub 515c619bc2 checkpoint postgres,sqlite: update version (#1812) 2024-09-23 17:33:19 -04:00
Nuno Campos e71c24ea9b Raise exception if sync method on async checkpointer is called from main thread
- The thread running the event loop can block waiting for a coro to run, only background threads can
2024-09-23 08:41:57 -07:00
Nuno CamposandGitHub 0bbe461785 Merge pull request #1771 from langchain-ai/nc/19sep/mypy-langgraph-partial
Enable mypy for langgraph lib
2024-09-19 16:53:42 -07:00
Nuno Campos cc318b1156 Fix 2024-09-19 11:43:30 -07:00
Nuno Campos fdf7bad988 Remove ignore for 3.9 2024-09-19 09:19:00 -07:00
Nuno Campos 495d258322 Fix 3.9 2024-09-19 08:50:17 -07:00
Nuno Campos b8a8651c23 ci: Enable mypy checks for checkpoint-postgres lib 2024-09-19 08:40:31 -07:00
Nuno Campos 4d0c12117b postgres 1.0.7 2024-09-16 14:10:19 -07:00
Nuno CamposandGitHub 3b05279e32 Implement serialization with msgpack library (#1716)
* Implement serialization with msgpack library

- encode custom python objects with a msgpack extension type, with constructor path string, and args encoded as nested msgpack doc

* Smaller msgpack extension types

* Update lock files

* lock

* Don't delegate to pydantic json

* Fix kafka serde

- should use our serializer to load, as inputs to subgraphs are serialized using it
2024-09-16 14:06:42 -07:00
c3b4acf3f1 checkpoint postgres: allow passing custom serde (#1699)
* Use correct serde in postgres checkpoint

* Revert metadata serde

* Revert

---------

Co-authored-by: Vadym Barda <vadym@langchain.dev>
2024-09-12 21:09:23 -07:00
Nuno CamposandGitHub 66fc7c96aa More performance improvements in checkpointing and channels (#1685)
* Performance improvements in checkpointer libs

- Use sha1 instead of md5 for hashing (faster in python 3.x)
- Use orjson instead of json for json dumping (sadly can't use for json loading)

* Update tests

* Update

* Use random number instead of hash for get_version_number

* Avoid saving writes for the last task to complete in each step

- only when possible, exceptions for ERROR, INTERRUPT, SEND

* Make Channel.from_checkpoint a regular function

- context manager no longer needed since Context became a managed value

* Use __slots__ for Channels

* Fix for kafka
2024-09-12 21:08:30 -07:00
Nuno Campos 270559b880 Implement changes in sqlite checkpointer 2024-09-10 16:17:22 -07:00
Nuno Campos 8f91402642 Use thread_id for partition key, ignore tasks for stale checkpoints 2024-09-10 16:17:22 -07:00
Nuno Campos b13db42568 WIP Subgraphs 2024-09-10 16:17:22 -07:00
Nuno Campos 6e9f54e5ae postgres 1.0.6 2024-09-02 17:57:55 -07:00
Nuno Campos dd4a15b569 Require latest version of langgraph-checkpoint 2024-09-02 17:57:33 -07:00
Nuno Campos 3b2a237deb Lint 2024-09-02 17:45:57 -07:00