Skip to content

Commit 5ffcd01

Browse files
docs: Register langchain-singlestore integration (#30841)
I created and published `langchain-singlestoe` integration package that should replace SingleStoreDB community implementation.
1 parent 096f0e5 commit 5ffcd01

File tree

6 files changed

+904
-3
lines changed

6 files changed

+904
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "e49f1e0d",
6+
"metadata": {},
7+
"source": [
8+
"# SingleStoreSemanticCache\n",
9+
"\n",
10+
"This example demonstrates how to get started with the SingleStore semantic cache.\n",
11+
"\n",
12+
"### Integration Overview\n",
13+
"\n",
14+
"`SingleStoreSemanticCache` leverages `SingleStoreVectorStore` to cache LLM responses directly in a SingleStore database, enabling efficient semantic retrieval and reuse of results.\n",
15+
"\n",
16+
"### Integration details\n",
17+
"\n",
18+
"\n",
19+
"\n",
20+
"| Class | Package | JS support |\n",
21+
"| :--- | :--- | :---: |\n",
22+
"| SingleStoreSemanticCache | langchain_singlestore | ❌ | "
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"id": "0730d6a1-c893-4840-9817-5e5251676d5d",
28+
"metadata": {},
29+
"source": [
30+
"## Installation\n",
31+
"\n",
32+
"This cache lives in the `langchain-singlestore` package:"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "652d6238-1f87-422a-b135-f5abbb8652fc",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"%pip install -qU langchain-singlestore"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"id": "5c5f2839-4020-424e-9fc9-07777eede442",
48+
"metadata": {},
49+
"source": [
50+
"## Usage"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"id": "51a60dbe-9f2e-4e04-bb62-23968f17164a",
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"from langchain_core.globals import set_llm_cache\n",
61+
"from langchain_singlestore import SingleStoreSemanticCache\n",
62+
"\n",
63+
"set_llm_cache(\n",
64+
" SingleStoreSemanticCache(\n",
65+
" embedding=YourEmbeddings(),\n",
66+
" host=\"root:pass@localhost:3306/db\",\n",
67+
" )\n",
68+
")"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": null,
74+
"id": "cddda8ef",
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"%%time\n",
79+
"# The first time, it is not yet in cache, so it should take longer\n",
80+
"llm.invoke(\"Tell me a joke\")"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"id": "c474168f",
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"%%time\n",
91+
"# The second time, while not a direct hit, the question is semantically similar to the original question,\n",
92+
"# so it uses the cached result!\n",
93+
"llm.invoke(\"Tell me one joke\")"
94+
]
95+
}
96+
],
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": "langchain-singlestore-BD1RbQ07-py3.11",
100+
"language": "python",
101+
"name": "python3"
102+
},
103+
"language_info": {
104+
"codemirror_mode": {
105+
"name": "ipython",
106+
"version": 3
107+
},
108+
"file_extension": ".py",
109+
"mimetype": "text/x-python",
110+
"name": "python",
111+
"nbconvert_exporter": "python",
112+
"pygments_lexer": "ipython3",
113+
"version": "3.11.11"
114+
}
115+
},
116+
"nbformat": 4,
117+
"nbformat_minor": 5
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"---\n",
8+
"sidebar_label: SingleStore\n",
9+
"---"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# SingleStoreLoader\n",
17+
"\n",
18+
"The `SingleStoreLoader` allows you to load documents directly from a SingleStore database table. It is part of the `langchain-singlestore` integration package.\n",
19+
"\n",
20+
"## Overview\n",
21+
"\n",
22+
"### Integration Details\n",
23+
"\n",
24+
"| Class | Package | JS Support |\n",
25+
"| :--- | :--- | :---: |\n",
26+
"| `SingleStoreLoader` | `langchain_singlestore` | ❌ |\n",
27+
"\n",
28+
"### Features\n",
29+
"- Load documents lazily to handle large datasets efficiently.\n",
30+
"- Supports native asynchronous operations.\n",
31+
"- Easily configurable to work with different database schemas.\n",
32+
"\n",
33+
"## Setup\n",
34+
"\n",
35+
"To use the `SingleStoreLoader`, you need to install the `langchain-singlestore` package. Follow the installation instructions below."
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {},
41+
"source": [
42+
"### Installation\n",
43+
"\n",
44+
"Install **langchain_singlestore**."
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {},
51+
"outputs": [],
52+
"source": [
53+
"%pip install -qU langchain_singlestore"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {},
59+
"source": [
60+
"## Initialization\n",
61+
"\n",
62+
"To initialize `SingleStoreLoader`, you need to provide connection parameters for the SingleStore database and specify the table and fields to load documents from.\n",
63+
"\n",
64+
"### Required Parameters:\n",
65+
"- **host** (`str`): Hostname, IP address, or URL for the database.\n",
66+
"- **table_name** (`str`): Name of the table to query. Defaults to `embeddings`.\n",
67+
"- **content_field** (`str`): Field containing document content. Defaults to `content`.\n",
68+
"- **metadata_field** (`str`): Field containing document metadata. Defaults to `metadata`.\n",
69+
"\n",
70+
"### Optional Parameters:\n",
71+
"- **id_field** (`str`): Field containing document IDs. Defaults to `id`.\n",
72+
"\n",
73+
"### Connection Pool Parameters:\n",
74+
"- **pool_size** (`int`): Number of active connections in the pool. Defaults to `5`.\n",
75+
"- **max_overflow** (`int`): Maximum connections beyond `pool_size`. Defaults to `10`.\n",
76+
"- **timeout** (`float`): Connection timeout in seconds. Defaults to `30`.\n",
77+
"\n",
78+
"### Additional Options:\n",
79+
"- **pure_python** (`bool`): Enables pure Python mode.\n",
80+
"- **local_infile** (`bool`): Allows local file uploads.\n",
81+
"- **charset** (`str`): Character set for string values.\n",
82+
"- **ssl_key**, **ssl_cert**, **ssl_ca** (`str`): Paths to SSL files.\n",
83+
"- **ssl_disabled** (`bool`): Disables SSL.\n",
84+
"- **ssl_verify_cert** (`bool`): Verifies server's certificate.\n",
85+
"- **ssl_verify_identity** (`bool`): Verifies server's identity.\n",
86+
"- **autocommit** (`bool`): Enables autocommits.\n",
87+
"- **results_type** (`str`): Structure of query results (e.g., `tuples`, `dicts`)."
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"metadata": {},
94+
"outputs": [],
95+
"source": [
96+
"from langchain_singlestore.document_loaders import SingleStoreLoader\n",
97+
"\n",
98+
"loader = SingleStoreLoader(\n",
99+
" host=\"127.0.0.1:3306/db\",\n",
100+
" table_name=\"documents\",\n",
101+
" content_field=\"content\",\n",
102+
" metadata_field=\"metadata\",\n",
103+
" id_field=\"id\",\n",
104+
")"
105+
]
106+
},
107+
{
108+
"cell_type": "markdown",
109+
"metadata": {},
110+
"source": [
111+
"## Load"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": [
120+
"docs = loader.load()\n",
121+
"docs[0]"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": null,
127+
"metadata": {},
128+
"outputs": [],
129+
"source": [
130+
"print(docs[0].metadata)"
131+
]
132+
},
133+
{
134+
"cell_type": "markdown",
135+
"metadata": {},
136+
"source": [
137+
"## Lazy Load"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {},
144+
"outputs": [],
145+
"source": [
146+
"page = []\n",
147+
"for doc in loader.lazy_load():\n",
148+
" page.append(doc)\n",
149+
" if len(page) >= 10:\n",
150+
" # do some paged operation, e.g.\n",
151+
" # index.upsert(page)\n",
152+
"\n",
153+
" page = []"
154+
]
155+
},
156+
{
157+
"cell_type": "markdown",
158+
"metadata": {},
159+
"source": [
160+
"## API reference\n",
161+
"\n",
162+
"For detailed documentation of all SingleStore Document Loader features and configurations head to the github page: [https://github.com/singlestore-labs/langchain-singlestore/](https://github.com/singlestore-labs/langchain-singlestore/)"
163+
]
164+
}
165+
],
166+
"metadata": {
167+
"kernelspec": {
168+
"display_name": "Python 3 (ipykernel)",
169+
"language": "python",
170+
"name": "python3"
171+
},
172+
"language_info": {
173+
"codemirror_mode": {
174+
"name": "ipython",
175+
"version": 3
176+
},
177+
"file_extension": ".py",
178+
"mimetype": "text/x-python",
179+
"name": "python",
180+
"nbconvert_exporter": "python",
181+
"pygments_lexer": "ipython3",
182+
"version": "3.11.9"
183+
}
184+
},
185+
"nbformat": 4,
186+
"nbformat_minor": 4
187+
}

docs/docs/integrations/llm_caching.ipynb

+13-3
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,17 @@
25252525
"source": [
25262526
"## `SingleStoreDB` semantic cache\n",
25272527
"\n",
2528-
"You can use [SingleStoreDB](https://python.langchain.com/docs/integrations/vectorstores/singlestoredb/) as a semantic cache to cache prompts and responses."
2528+
"You can use [SingleStore](https://python.langchain.com/docs/integrations/vectorstores/singlestore/) as a semantic cache to cache prompts and responses."
2529+
]
2530+
},
2531+
{
2532+
"cell_type": "code",
2533+
"execution_count": null,
2534+
"id": "596e15e8",
2535+
"metadata": {},
2536+
"outputs": [],
2537+
"source": [
2538+
"%pip install -qU langchain-singlestore"
25292539
]
25302540
},
25312541
{
@@ -2535,11 +2545,11 @@
25352545
"metadata": {},
25362546
"outputs": [],
25372547
"source": [
2538-
"from langchain_community.cache import SingleStoreDBSemanticCache\n",
25392548
"from langchain_openai import OpenAIEmbeddings\n",
2549+
"from langchain_singlestore.cache import SingleStoreSemanticCache\n",
25402550
"\n",
25412551
"set_llm_cache(\n",
2542-
" SingleStoreDBSemanticCache(\n",
2552+
" SingleStoreSemanticCache(\n",
25432553
" embedding=OpenAIEmbeddings(),\n",
25442554
" host=\"root:pass@localhost:3306/db\",\n",
25452555
" )\n",

0 commit comments

Comments
 (0)