|
| 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 | +} |
0 commit comments