An integration package connecting AlibabaCloud RDS MySQL (with Vector support) and LangChain
Project description
🦜️🔗 LangChain AlibabaCloud MySQL
This package provides LangChain integration with AlibabaCloud RDS MySQL's native vector search capabilities.
Requirements
- Python 3.10+
- AlibabaCloud RDS MySQL 8.0.36+ with Vector support
- rds_release_date >= 20251031
Installation
pip install -U langchain-alibabacloud-mysql
Optional Dependencies
For DashScope embeddings (recommended for Alibaba Cloud):
pip install langchain-community dashscope
Quick Start
Using DashScope Embeddings (Recommended)
from langchain_alibabacloud_mysql import AlibabaCloudMySQL
from langchain_community.embeddings import DashScopeEmbeddings
embeddings = DashScopeEmbeddings(
model="text-embedding-v4",
dashscope_api_key="your-dashscope-api-key",
)
vectorstore = AlibabaCloudMySQL(
host="your-rds-host.mysql.rds.aliyuncs.com",
port=3306,
user="your-user",
password="your-password",
database="your-database",
embedding=embeddings,
table_name="langchain_vectors",
distance_strategy="cosine",
hnsw_m=6,
)
# Add texts
vectorstore.add_texts(["Hello world", "LangChain is great"])
# Search
results = vectorstore.similarity_search("Hello", k=2)
Using Other Embedding Models
Any LangChain-compatible embedding model can be used:
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
# ... rest remains the same
Features
- Native VECTOR data type for efficient storage
- HNSW vector index for fast approximate nearest neighbor search
- Cosine and Euclidean distance metrics
- MMR search for diverse results
- Metadata filtering support
- Batch operations for efficient data loading
API Reference
AlibabaCloudMySQL
Main vector store class.
Constructor Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
host |
str | - | MySQL host |
port |
int | - | MySQL port |
user |
str | - | Username |
password |
str | - | Password |
database |
str | - | Database name |
embedding |
Embeddings | - | Embedding model |
table_name |
str | "langchain_vectors" | Table name |
distance_strategy |
str | "cosine" | "cosine" or "euclidean" |
hnsw_m |
int | 6 | HNSW M parameter |
Methods:
add_texts(texts, metadatas, ids)- Add texts to the storesimilarity_search(query, k, filter)- Search for similar documentssimilarity_search_with_score(query, k, filter)- Search with similarity scoresmax_marginal_relevance_search(query, k, fetch_k, lambda_mult, filter)- MMR searchdelete(ids)- Delete vectors by IDsget_by_ids(ids)- Get documents by IDscount()- Count total vectorsclear()- Clear all vectorsdrop_table()- Drop the vector tablefrom_texts(texts, embedding, ...)- Create from textsfrom_documents(documents, embedding, ...)- Create from documents
Demo Tests
See tests/demo_tests/ for comprehensive examples:
RAG-agent.py- RAG agent with retrieval toolsfilter-query.py- Metadata filtering examplessemantic-search.py- Basic similarity search
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_alibabacloud_mysql-1.0.1.tar.gz.
File metadata
- Download URL: langchain_alibabacloud_mysql-1.0.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b729e13a41e9b80d4a14695565bf800eb8251568d6f1dc45e98b10565eb228c2
|
|
| MD5 |
944624b5ec40379d1f465c4c8ac53ea2
|
|
| BLAKE2b-256 |
a6b9d3f3b59b1e055f048593efe39f52ab78ce5347d18241d0216a27ee5d75e5
|
File details
Details for the file langchain_alibabacloud_mysql-1.0.1-py3-none-any.whl.
File metadata
- Download URL: langchain_alibabacloud_mysql-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adc050b16b0e4bcf1e33ca27a34faedd0337200efcae050ffe92a019ec637ae1
|
|
| MD5 |
388f5488f159811d592dba49af534d67
|
|
| BLAKE2b-256 |
928b4577bcb42189fdbd56aef44c38f7cba47051114402af6577da7bbdb0ca67
|