Skip to main content

langchain-shannonbase

A LangChain VectorStore for MySQL 9's native VECTOR type — so you can do RAG on a database you already run.

Works with ShannonBase (the open-source MySQL-for-AI), self-hosted MySQL 9, and MySQL HeatWave — they all share the same VECTOR / STRING_TO_VECTOR / DISTANCE surface.

Why this exists

If your data already lives in MySQL, your options for LangChain vector search were thin: the only MySQL VectorStore is locked to Google Cloud SQL, and ShannonBase's LangChain integration was on its wishlist but unbuilt. This fills that gap — a plain, self-hostable adapter that plugs MySQL 9 into the LangChain ecosystem, no separate vector database required.

Install

pip install "langchain-shannonbase[mysql]"

Use

from langchain_openai import OpenAIEmbeddings
from langchain_shannonbase import ShannonBaseVectorStore

store = ShannonBaseVectorStore(
    embedding=OpenAIEmbeddings(model="text-embedding-3-small"),
    table="documents",
    host="127.0.0.1", port=3306, user="root", password="", database="rag",
)

store.add_texts(
    ["Refunds are accepted within 30 days.", "Free shipping over $50."],
    metadatas=[{"topic": "refunds"}, {"topic": "shipping"}],
)

# It's a normal LangChain vector store — use it directly or as a retriever:
docs = store.similarity_search("return policy?", k=2)
retriever = store.as_retriever(search_kwargs={"k": 3})

Because it implements LangChain's VectorStore interface, it drops into any LangChain chain, retriever, or RAG pipeline unchanged.

How it works

Under the hood it uses MySQL 9's native vector features — no extensions:

CREATE TABLE documents (
  id VARCHAR(36) PRIMARY KEY,
  content TEXT, metadata JSON,
  embedding VECTOR(1536)
);
-- inserts go through STRING_TO_VECTOR('[...]')
-- search: ORDER BY DISTANCE(embedding, STRING_TO_VECTOR('[...]'), 'COSINE')

Similarity search reads back the nearest rows by cosine distance and returns them as LangChain Documents with a score (1 - distance).

API

Method Does
add_texts(texts, metadatas, ids) embed + upsert, returns ids
similarity_search(query, k) top-k Documents
similarity_search_with_score(query, k) with cosine similarity scores
similarity_search_by_vector(embedding, k) search with a raw vector
delete(ids) remove by id
from_texts(texts, embedding, ...) build a store in one call
metric= "cosine" (default), "dot", "euclidean"

Testing

The core logic is unit-tested offline via an in-memory backend (no database needed — pytest). A live round-trip test runs against a real instance when you set the connection env vars:

export SB_HOST=127.0.0.1 SB_USER=root SB_PASSWORD=... SB_DATABASE=test
pytest tests/test_integration.py

Local dev tip: run ShannonBase to get MySQL-9 vector features without a HeatWave subscription.

Requirements

  • Python 3.9+
  • A MySQL-9-compatible database with the VECTOR type (ShannonBase, MySQL 9, or HeatWave)
  • mysql-connector-python (installed via the [mysql] extra)

License

MIT © Apoorva Verma

Metadata

Release files for langchain-shannonbase 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-shannonbase 0.1.0
File Size Uploaded
langchain_shannonbase-0.1.0.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-shannonbase 0.1.0
File Interpreter ABI Platform
langchain_shannonbase-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / langchain_shannonbase-0.1.0.tar.gz

Download URL langchain_shannonbase-0.1.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
10252b69d7d0116f1187593607918c57a20a36f4c522c897dffce7c85603e0bf
BLAKE2b-256 checksum
How to use checksums
ff556372a3e3e087028e9712c0088af5f75abf4f6b13879a4ddd3ca7ddb1d17b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 18, 2026.

Transparency log

Release files / langchain_shannonbase-0.1.0-py3-none-any.whl

Download URL langchain_shannonbase-0.1.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3cceb42fa3bcc44db910d84677ff9e55b919602dfc699dbbbc4115e72bb3e2da
BLAKE2b-256 checksum
How to use checksums
84bda94497849494de9f0721026fa3533b8a343cc6f075efaf5399e011e666e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 18, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page