English | 中文README
LangChain – Volcengine MySQL Ecosystem
A unified, lightweight adapter package for LangChain users who work with MySQL in Volcengine environments. It provides one import surface for two powerful, externally-available database backends:
- veDB for MySQL: A cloud-native, high-performance database service from Volcengine.
- RDS for MySQL: A fully managed, stable, and scalable relational database service.
Both adapters are bundled in this package, offering a consistent, attribute-style API for creating and using vector stores and retrievers.
Overview
Official docs: veDB for MySQL · RDS for MySQL
This package simplifies using veDB for MySQL and RDS for MySQL as vector stores in LangChain applications. It abstracts the backend-specific details and provides a clean, unified interface.
- For veDB for MySQL: It leverages the
vedbsearchclient library for efficient vector search. - For RDS for MySQL: It utilizes the native vector indexing and search capabilities available in recent versions.
Features
-
Unified API: A single package to interact with both veDB for MySQL and RDS for MySQL.
-
Attribute-style Access: Use
vedb.vector_storeandmysql.vector_storeto get configured vector store instances. -
Easy Configuration: Configure database connections and embedding functions with
configure()andset_embedding(). -
Standard LangChain Integration: Fully compatible with the LangChain ecosystem, including chains and other components.
Installation
Install the unified SDK:
pip install langchain-volcengine-mysql
This single installation includes all necessary components to connect to both veDB for MySQL and RDS for MySQL.
Import Style & Backend Selection
Select the backend by importing the corresponding submodule and configuring defaults.
# veDB for MySQL
from langchain_volcengine_mysql import vedb
vedb.configure(host="...", user="...", password="...", database="...", table_name="...", embedding_function=embeddings)
vector_store = vedb.vector_store
retriever = vedb.retriever
# RDS for MySQL
from langchain_volcengine_mysql import mysql
mysql.configure(host="...", user="...", password="...", database="...", table_name="...", embedding_function=embeddings)
vector_store = mysql.vector_store
retriever = mysql.retriever
Quickstart
Choose a backend by importing the corresponding submodule. Then, configure it and access the vector_store or retriever attributes.
Vector Store (veDB for MySQL)
from langchain_core.embeddings import FakeEmbeddings
from langchain_volcengine_mysql import vedb
# 1. Configure the connection and embedding function
embeddings = FakeEmbeddings(size=768)
vedb.configure(
host="your-vedb-host.example.com",
port=3306,
user="your_user",
password="your_password",
database="your_db",
table_name="vector_embeddings",
embedding_dim=768,
embedding_function=embeddings,
)
# 2. Access the vector store and retriever
vector_store = vedb.vector_store
retriever = vedb.retriever
# 3. Add texts and perform searches
vector_store.add_texts(
[
"veDB for MySQL is a cloud-native database in Volcengine.",
"LangChain is a framework for building LLM applications.",
],
metadatas=[{"source": "doc1"}, {"source": "doc2"}],
)
# Similarity search via vector store
results = vector_store.similarity_search("What is veDB?", k=1)
print(results)
# Retriever usage: fetch relevant documents
docs = retriever.get_relevant_documents("What is veDB?")
print([d.page_content for d in docs])
Vector Store (RDS for MySQL)
from langchain_core.embeddings import FakeEmbeddings
from langchain_volcengine_mysql import mysql
# 1. Configure the connection and embedding function
embeddings = FakeEmbeddings(size=1024)
mysql.configure(
host="your-mysql-host.example.com",
port=3306,
user="your_user",
password="your_password",
database="your_db",
table_name="langchain_vectors",
embedding_function=embeddings,
)
# 2. Access the vector store and retriever
vector_store = mysql.vector_store
retriever = mysql.retriever
# 3. Add texts and perform searches
vector_store.add_texts(
["Example sentence one.", "Example sentence two."],
metadatas=[{"source": "demo1"}, {"source": "demo2"}],
)
# Similarity search via vector store
print(vector_store.similarity_search("Example", k=2))
# Retriever usage: fetch relevant documents
docs = retriever.get_relevant_documents("Example")
print([d.page_content for d in docs])
Configuration
Configuration is handled at the module level using the configure() function.
Configuration Parameters
| Parameter | Type | Description | veDB | RDS |
|---|---|---|---|---|
host |
str |
Database host. | ✅ | ✅ |
port |
int |
Database port. | ✅ | ✅ |
user |
str |
Database user. | ✅ | ✅ |
password |
str |
Database password. | ✅ | ✅ |
database |
str |
Database name. | ✅ | ✅ |
table_name |
str |
Table for storing vectors. | ✅ | ✅ |
embedding_function |
Embeddings |
LangChain embeddings model. | ✅ | ✅ |
embedding_dim |
int |
Dimension of the vectors. | ✅ | ❌ |
index_name |
str |
Name of the vector index. | ❌ | ✅ |
distance |
MySQLVectorDistance or str |
Distance metric for search. | ❌ | ✅ |
Environment Variables
As an alternative to configure(), you can set environment variables for the connection parameters. The embedding_function must still be set using set_embedding().
Getting a Volcano Engine Account & veDB/RDS for MySQL (Quick Guide)
- Sign up or log in to the Volcano Engine Console.
- Enable the veDB for MySQL or RDS for MySQL service.
- Create a MySQL-compatible instance.
- Note your connection info: host, port, database, user, password.
- Configure IP allowlist and TLS if required.
- Map these values into the SDK via
vedb.configure(...)/mysql.configure(...).
# veDB for MySQL
from langchain_volcengine_mysql import vedb
vedb.configure(
host="vedb-host.example.com",
port=3306,
user="admin",
password="***",
database="app_db",
table_name="vectors",
embedding_function=embeddings,
)
# RDS for MySQL
from langchain_volcengine_mysql import mysql
mysql.configure(
host="rds-host.example.com",
port=3306,
user="admin",
password="***",
database="app_db",
table_name="vectors",
embedding_function=embeddings,
)
For full provisioning steps and pricing, refer to Volcano Engine official docs.
API Reference
Submodules
-
langchain_volcengine_mysql.vedb:vector_store: Attribute to get a configuredVectorStoreinstance.retriever: Attribute to get a configuredVectorStoreRetriever.configure(**config): Sets the default configuration for the module.set_embedding(embedding_function): Sets the embedding function.
-
langchain_volcengine_mysql.mysql:vector_store: Attribute to get a configuredVectorStoreinstance.retriever: Attribute to get a configuredVectorStoreRetriever.configure(**config): Sets the default configuration for the module.set_embedding(embedding_function): Sets the embedding function.
Advanced Usage
Using the Retriever with Chains
The retriever can be seamlessly integrated into LangChain chains.
from langchain.chains import RetrievalQA
from langchain_community.llms import FakeStreamingLLM
# Assuming `mysql.retriever` is already configured
retriever = mysql.retriever
# Create a QA chain
qa_chain = RetrievalQA.from_chain_type(
llm=FakeStreamingLLM(),
chain_type="stuff",
retriever=retriever,
)
# Run the chain
question = "What is an example sentence?"
response = qa_chain.run(question)
print(response)
Schema and Index Management (RDS for MySQL)
The RDS for MySQL vector store provides helper methods to manage the database schema and vector index.
# Create the table and HNSW index
vector_store.create_schema(
table_name="my_documents",
vector_size=1024,
algorithm_params={"distance": "l2", "M": 16, "ef_construction": 100},
)
# Drop the index
vector_store.drop_index()
# Drop the table
vector_store.drop_table()
Troubleshooting
ConfigError: Raised if required configuration parameters are missing when accessingvector_storeorretriever. Ensure you have calledconfigure()with all necessary parameters.- Connection Issues: Verify that the host, port, user, password, and database are correct and that the network connection to the database is allowed.
- veDB Dependencies: The veDB adapter relies on the
vedbsearchclient library. If you encounter issues, ensure it is correctly installed and configured in your environment.
Security
If you discover a potential security issue in this project, please notify ByteDance Security via our security center or by emailing sec@bytedance.com. Please do not create a public GitHub issue.
Code of Conduct
Please see the CODE_OF_CONDUCT.md file for details.
Contributing
Please see the CONTRIBUTING.md file for details.
License
This project is licensed under the Apache-2.0 License.
Metadata
Release files for langchain-volcengine-mysql 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_volcengine_mysql-0.1.0.tar.gz | 47.9 kB | Without provenance | Details for langchain_volcengine_mysql-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_volcengine_mysql-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_volcengine_mysql-0.1.0-py3-none-any.whl |
Total release size: 81.3 kB
Release files / langchain_volcengine_mysql-0.1.0.tar.gz
| Download URL | langchain_volcengine_mysql-0.1.0.tar.gz |
|---|---|
| Size | 47.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b606d89b4f3f7e106f64fc25f90e1184f2491ca7c00f43d8511a35b5216300d
|
|
BLAKE2b-256 checksum How to use checksums |
4fa67405bc7fe94db3e6f25d1f4fbdc86c58f24fd330c78cb0bef1e38a2006b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.13
|
Release files / langchain_volcengine_mysql-0.1.0-py3-none-any.whl
| Download URL | langchain_volcengine_mysql-0.1.0-py3-none-any.whl |
|---|---|
| Size | 33.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4942690e56c44afa5fc370953a335b38a006a7c62407f66f4964aa0a4e90953e
|
|
BLAKE2b-256 checksum How to use checksums |
fb97e4529f976060d5aefd9965ddd2055d0cecfd3dff390551610fd57723e98a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.13
|
Security for langchain-volcengine-mysql 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.