-
Notifications
You must be signed in to change notification settings - Fork 15.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core[patch], langchain[patch]: ByteStore #14312
Merged
efriis
merged 13 commits into
master
from
erick/core-patch---langchain-patch---bytes-store-wip-
Dec 6, 2023
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c791ae6
core[patch], langchain[patch]: bytes store wip
efriis 9d3ce04
covariant BaseStore V
efriis ce9ec91
left out a file
efriis d0c8abb
Merge branch 'master' into erick/core-patch---langchain-patch---bytes…
efriis f5a026e
docs
efriis 3260321
wip docs
efriis 600e9d7
cache embeddings
efriis e7774ed
redis
efriis 57fdbbb
Merge branch 'master' into erick/core-patch---langchain-patch---bytes…
efriis 8ea3648
upstash redis
efriis 6545d30
no covariant
efriis d469488
format docs
efriis 30f0d8e
import list
efriis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,24 @@ Install the Python SDK: | |
pip install redis | ||
``` | ||
|
||
To run Redis locally, you can use Docker: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. help people get started faster with redis |
||
|
||
```bash | ||
docker run --name langchain-redis -d -p 6379:6379 redis redis-server --save 60 1 --loglevel warning | ||
``` | ||
|
||
To stop the container: | ||
|
||
```bash | ||
docker stop langchain-redis | ||
``` | ||
|
||
And to start it again: | ||
|
||
```bash | ||
docker start langchain-redis | ||
``` | ||
|
||
## Wrappers | ||
|
||
All wrappers need a redis url connection string to connect to the database support either a stand alone Redis server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "raw", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"sidebar_label: Local Filesystem\n", | ||
"sidebar_position: 3\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# LocalFileStore\n", | ||
"\n", | ||
"The `LocalFileStore` is a persistent implementation of `ByteStore` that stores everything in a folder of your choosing." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[b'v1', b'v2']\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"from langchain.storage import LocalFileStore\n", | ||
"\n", | ||
"root_path = Path.cwd() / 'data' # can also be a path set by a string\n", | ||
"store = LocalFileStore(root_path)\n", | ||
"\n", | ||
"store.mset([('k1', b'v1'), ('k2', b'v2')])\n", | ||
"print(store.mget(['k1', 'k2']))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now let's see which files exist in our `data` folder:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"k1 k2\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"!ls {root_path}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "raw", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"sidebar_label: In Memory\n", | ||
"sidebar_position: 2\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# InMemoryByteStore\n", | ||
"\n", | ||
"The `InMemoryByteStore` is a non-persistent implementation of `ByteStore` that stores everything in a Python dictionary." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[b'v1', b'v2']\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from langchain.storage import InMemoryByteStore\n", | ||
"\n", | ||
"store = InMemoryByteStore()\n", | ||
"\n", | ||
"store.mset([('k1', b'v1'), ('k2', b'v2')])\n", | ||
"print(store.mget(['k1', 'k2']))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
sidebar_position: 1 | ||
sidebar_class_name: hidden | ||
--- | ||
|
||
# Stores | ||
|
||
In many different applications, having some sort of key-value storage is helpful. | ||
In this section, we will look at a few different ways to store key-value pairs | ||
using implementations of the `ByteStore` interface. | ||
|
||
## Features (natively supported) | ||
|
||
All `ByteStore`s support the following functions, which are used for modifying | ||
**m**ultiple key-value pairs at once: | ||
|
||
- `mget(key: Sequence[str]) -> List[Optional[bytes]]`: get the contents of multiple keys, returning `None` if the key does not exist | ||
- `mset(key_value_pairs: Sequence[Tuple[str, bytes]]) -> None`: set the contents of multiple keys | ||
- `mdelete(key: Sequence[str]) -> None`: delete multiple keys | ||
- `yield_keys(prefix: Optional[str] = None) -> Iterator[str]`: yield all keys in the store, optionally filtering by a prefix | ||
|
||
## How to pick one | ||
|
||
`ByteStore`s are designed to be interchangeable. By default, most dependent integrations | ||
use the `InMemoryByteStore`, which is a simple in-memory key-value store. | ||
|
||
However, if you start having other requirements, like massive scalability or persistence, | ||
you can swap out the `ByteStore` implementation with one of the other ones documented | ||
in this section. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "raw", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"sidebar_label: Redis\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# RedisStore\n", | ||
"\n", | ||
"The `RedisStore` is an implementation of `ByteStore` that stores everything in your Redis instance.\n", | ||
"\n", | ||
"To configure Redis, follow our [Redis guide](/docs/integrations/providers/redis)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install redis" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[b'v1', b'v2']\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from langchain.storage import RedisStore\n", | ||
"\n", | ||
"store = RedisStore(redis_url=\"redis://localhost:6379\")\n", | ||
"\n", | ||
"store.mset([(\"k1\", b\"v1\"), (\"k2\", b\"v2\")])\n", | ||
"print(store.mget([\"k1\", \"k2\"]))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated docs local build change