langchain/docs/docs/integrations/document_loaders/singlestore.ipynb
Volodymyr Tkachuk 5ffcd01c41
docs: Register langchain-singlestore integration (#30841)
I created and published `langchain-singlestoe` integration package that
should replace SingleStoreDB community implementation.
2025-04-18 12:11:33 -04:00

188 lines
5.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"sidebar_label: SingleStore\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# SingleStoreLoader\n",
"\n",
"The `SingleStoreLoader` allows you to load documents directly from a SingleStore database table. It is part of the `langchain-singlestore` integration package.\n",
"\n",
"## Overview\n",
"\n",
"### Integration Details\n",
"\n",
"| Class | Package | JS Support |\n",
"| :--- | :--- | :---: |\n",
"| `SingleStoreLoader` | `langchain_singlestore` | ❌ |\n",
"\n",
"### Features\n",
"- Load documents lazily to handle large datasets efficiently.\n",
"- Supports native asynchronous operations.\n",
"- Easily configurable to work with different database schemas.\n",
"\n",
"## Setup\n",
"\n",
"To use the `SingleStoreLoader`, you need to install the `langchain-singlestore` package. Follow the installation instructions below."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Installation\n",
"\n",
"Install **langchain_singlestore**."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install -qU langchain_singlestore"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialization\n",
"\n",
"To initialize `SingleStoreLoader`, you need to provide connection parameters for the SingleStore database and specify the table and fields to load documents from.\n",
"\n",
"### Required Parameters:\n",
"- **host** (`str`): Hostname, IP address, or URL for the database.\n",
"- **table_name** (`str`): Name of the table to query. Defaults to `embeddings`.\n",
"- **content_field** (`str`): Field containing document content. Defaults to `content`.\n",
"- **metadata_field** (`str`): Field containing document metadata. Defaults to `metadata`.\n",
"\n",
"### Optional Parameters:\n",
"- **id_field** (`str`): Field containing document IDs. Defaults to `id`.\n",
"\n",
"### Connection Pool Parameters:\n",
"- **pool_size** (`int`): Number of active connections in the pool. Defaults to `5`.\n",
"- **max_overflow** (`int`): Maximum connections beyond `pool_size`. Defaults to `10`.\n",
"- **timeout** (`float`): Connection timeout in seconds. Defaults to `30`.\n",
"\n",
"### Additional Options:\n",
"- **pure_python** (`bool`): Enables pure Python mode.\n",
"- **local_infile** (`bool`): Allows local file uploads.\n",
"- **charset** (`str`): Character set for string values.\n",
"- **ssl_key**, **ssl_cert**, **ssl_ca** (`str`): Paths to SSL files.\n",
"- **ssl_disabled** (`bool`): Disables SSL.\n",
"- **ssl_verify_cert** (`bool`): Verifies server's certificate.\n",
"- **ssl_verify_identity** (`bool`): Verifies server's identity.\n",
"- **autocommit** (`bool`): Enables autocommits.\n",
"- **results_type** (`str`): Structure of query results (e.g., `tuples`, `dicts`)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain_singlestore.document_loaders import SingleStoreLoader\n",
"\n",
"loader = SingleStoreLoader(\n",
" host=\"127.0.0.1:3306/db\",\n",
" table_name=\"documents\",\n",
" content_field=\"content\",\n",
" metadata_field=\"metadata\",\n",
" id_field=\"id\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"docs = loader.load()\n",
"docs[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(docs[0].metadata)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lazy Load"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"page = []\n",
"for doc in loader.lazy_load():\n",
" page.append(doc)\n",
" if len(page) >= 10:\n",
" # do some paged operation, e.g.\n",
" # index.upsert(page)\n",
"\n",
" page = []"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## API reference\n",
"\n",
"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/)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}