docs[patch]: Adds first kv store doc matching new template (#24844)

This commit is contained in:
Jacob Lee 2024-07-30 15:58:51 -07:00 committed by GitHub
parent a4e940550a
commit 21eb4c9e5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 170 additions and 43 deletions

View File

@ -2,12 +2,14 @@
"cells": [ "cells": [
{ {
"cell_type": "raw", "cell_type": "raw",
"metadata": {}, "metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [ "source": [
"---\n", "---\n",
"sidebar_label: In Memory\n", "sidebar_label: InMemoryByteStore\n",
"sidebar_position: 2\n",
"keywords: [InMemoryStore]\n",
"---" "---"
] ]
}, },
@ -17,29 +19,26 @@
"source": [ "source": [
"# InMemoryByteStore\n", "# InMemoryByteStore\n",
"\n", "\n",
"The `InMemoryByteStore` is a non-persistent implementation of `ByteStore` that stores everything in a Python dictionary." "This guide will help you get started with in-memory [key-value stores](/docs/concepts/#key-value-stores). For detailed documentation of all `InMemoryByteStore` features and configurations head to the [API reference](https://api.python.langchain.com/en/latest/stores/langchain_core.stores.InMemoryByteStore.html).\n",
"\n",
"## Overview\n",
"\n",
"The `InMemoryByteStore` is a non-persistent implementation of a `ByteStore` that stores everything in a Python dictionary. It's intended for demos and cases where you don't need persistence past the lifetime of the Python process.\n",
"\n",
"### Integration details\n",
"\n",
"| Class | Package | Local | [JS support](https://js.langchain.com/v0.2/docs/integrations/stores/in_memory/) | Package downloads | Package latest |\n",
"| :--- | :--- | :---: | :---: | :---: | :---: | :---: |\n",
"| [InMemoryByteStore](https://api.python.langchain.com/en/latest/stores/langchain_core.stores.InMemoryByteStore.html) | [langchain_core](https://api.python.langchain.com/en/latest/core_api_reference.html) | ✅ | ✅ | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain_core?style=flat-square&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain_core?style=flat-square&label=%20) |"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[b'v1', b'v2']\n"
]
}
],
"source": [ "source": [
"from langchain.storage import InMemoryByteStore\n", "### Installation\n",
"\n", "\n",
"store = InMemoryByteStore()\n", "The LangChain `InMemoryByteStore` integration lives in the `langchain_core` package:"
"\n",
"store.mset([(\"k1\", b\"v1\"), (\"k2\", b\"v2\")])\n",
"print(store.mget([\"k1\", \"k2\"]))"
] ]
}, },
{ {
@ -47,12 +46,123 @@
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"%pip install -qU langchain_core"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Instantiation\n",
"\n",
"Now you can instantiate your byte store:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from langchain_core.stores import InMemoryByteStore\n",
"\n",
"kv_store = InMemoryByteStore()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Usage\n",
"\n",
"You can set data under keys like this using the `mset` method:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[b'value1', b'value2']"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kv_store.mset(\n",
" [\n",
" [\"key1\", b\"value1\"],\n",
" [\"key2\", b\"value2\"],\n",
" ]\n",
")\n",
"\n",
"kv_store.mget(\n",
" [\n",
" \"key1\",\n",
" \"key2\",\n",
" ]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And you can delete data using the `mdelete` method:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[None, None]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kv_store.mdelete(\n",
" [\n",
" \"key1\",\n",
" \"key2\",\n",
" ]\n",
")\n",
"\n",
"kv_store.mget(\n",
" [\n",
" \"key1\",\n",
" \"key2\",\n",
" ]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## API reference\n",
"\n",
"For detailed documentation of all `InMemoryByteStore` features and configurations, head to the API reference: https://api.python.langchain.com/en/latest/stores/langchain_core.stores.InMemoryByteStore.html"
]
} }
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": ".venv", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@ -66,7 +176,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.4" "version": "3.10.5"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -21,7 +21,7 @@
"\n", "\n",
"- TODO: Make sure API reference link is correct.\n", "- TODO: Make sure API reference link is correct.\n",
"\n", "\n",
"This will help you getting started with __ModuleName__ [key-value stores](/docs/concepts/#key-value-stores). For detailed documentation of all __ModuleName__ByteStore features and configurations head to the [API reference](https://api.python.langchain.com/en/latest/stores/langchain_core.stores.__module_name__ByteStore.html).\n", "This will help you get started with __ModuleName__ [key-value stores](/docs/concepts/#key-value-stores). For detailed documentation of all __ModuleName__ByteStore features and configurations head to the [API reference](https://api.python.langchain.com/en/latest/stores/langchain_core.stores.__module_name__ByteStore.html).\n",
"\n", "\n",
"- TODO: Add any other relevant links, like information about models, prices, context windows, etc. See https://python.langchain.com/v0.2/docs/integrations/stores/in_memory/ for an example.\n", "- TODO: Add any other relevant links, like information about models, prices, context windows, etc. See https://python.langchain.com/v0.2/docs/integrations/stores/in_memory/ for an example.\n",
"\n", "\n",
@ -113,7 +113,9 @@
"source": [ "source": [
"## Usage\n", "## Usage\n",
"\n", "\n",
"- TODO: Run cells so output can be seen." "- TODO: Run cells so output can be seen.\n",
"\n",
"You can set data under keys like this using the `mset` method:"
] ]
}, },
{ {
@ -122,15 +124,26 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"kv_store.mset([\n", "kv_store.mset(\n",
" [\n",
" [\"key1\", b\"value1\"],\n", " [\"key1\", b\"value1\"],\n",
" [\"key2\", b\"value2\"],\n", " [\"key2\", b\"value2\"],\n",
"])\n", " ]\n",
")\n",
"\n", "\n",
"kv_store.mget([\n", "kv_store.mget(\n",
" [\n",
" \"key1\",\n", " \"key1\",\n",
" \"key2\",\n", " \"key2\",\n",
"])" " ]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And you can delete data using the `mdelete` method:"
] ]
}, },
{ {
@ -139,15 +152,19 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"kv_store.mdelete([\n", "kv_store.mdelete(\n",
" [\n",
" \"key1\",\n", " \"key1\",\n",
" \"key2\",\n", " \"key2\",\n",
"])\n", " ]\n",
")\n",
"\n", "\n",
"kv_store.mget([\n", "kv_store.mget(\n",
" [\n",
" \"key1\",\n", " \"key1\",\n",
" \"key2\",\n", " \"key2\",\n",
"])" " ]\n",
")"
] ]
}, },
{ {
@ -165,7 +182,7 @@
"source": [ "source": [
"## API reference\n", "## API reference\n",
"\n", "\n",
"For detailed documentation of all __ModuleName__ByteStore features and configurations head to the API reference: https://api.python.langchain.com/en/latest/stores/__module_name__.stores.__ModuleName__ByteStore.html" "For detailed documentation of all __ModuleName__ByteStore features and configurations, head to the API reference: https://api.python.langchain.com/en/latest/stores/__module_name__.stores.__ModuleName__ByteStore.html"
] ]
} }
], ],