Skip to main content

LlamaIndex Graph Stores Integration: TiDB

TiDB is a distributed SQL database, it is MySQL compatible and features horizontal scalability, strong consistency, and high availability. Currently it also supports Vector Search in TiDB Cloud Serverless.

In this project, we integrate TiDB as the graph store to store the LlamaIndex graph data, and use TiDB's SQL interface to query the graph data. so that people can use TiDB to interact with LlamaIndex graph index.

  • Property Graph Store: TiDBPropertyGraphStore
  • Knowledge Graph Store: TiDBGraphStore

Installation

pip install llama-index llama-index-graph-stores-tidb

Usage

Property Graph Store

NOTE: TiDBPropertyGraphStore requires the Vector Search feature in TiDB, but now it is only available in TiDB Cloud Serverless.

Please checkout this tutorial to learn how to use TiDBPropertyGraphStore with LlamaIndex.

Simple example to use TiDBPropertyGraphStore:

from llama_index.core import PropertyGraphIndex, SimpleDirectoryReader
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
from llama_index.core.indices.property_graph import SchemaLLMPathExtractor
from llama_index.graph_stores.tidb import TiDBPropertyGraphStore

documents = SimpleDirectoryReader(
    "../../../examples/data/paul_graham/"
).load_data()

graph_store = TiDBPropertyGraphStore(
    db_connection_string="mysql+pymysql://user:password@host:4000/dbname?ssl_verify_cert=true&ssl_verify_identity=true",
)

index = PropertyGraphIndex.from_documents(
    documents,
    embed_model=OpenAIEmbedding(model_name="text-embedding-3-small"),
    kg_extractors=[
        SchemaLLMPathExtractor(
            llm=OpenAI(model="gpt-3.5-turbo", temperature=0.0)
        )
    ],
    property_graph_store=graph_store,
    show_progress=True,
)

query_engine = index.as_query_engine(include_text=True)
response = query_engine.query("What happened at Interleaf and Viaweb?")
print(response)

Knowledge Graph Store

Checkout this tutorial to learn how to use TiDBGraphStore with LlamaIndex.

For TiDBGraphStore, you can use either Self-Hosted TiDB or TiDB Cloud Serverless(Recommended).

Simple example to use TiDBGraphStore:

from llama_index.graph_stores.tidb import TiDBGraphStore
from llama_index.core import (
    KnowledgeGraphIndex,
    SimpleDirectoryReader,
    StorageContext,
)

documents = SimpleDirectoryReader(
    "../../../examples/data/paul_graham/"
).load_data()

graph_store = TiDBGraphStore(
    db_connection_string="mysql+pymysql://user:password@host:4000/dbname"
)
storage_context = StorageContext.from_defaults(graph_store=graph_store)
index = KnowledgeGraphIndex.from_documents(
    documents=documents,
    storage_context=storage_context,
    max_triplets_per_chunk=2,
)
query_engine = index.as_query_engine(
    include_text=False, response_mode="tree_summarize"
)
response = query_engine.query(
    "Tell me more about Interleaf",
)
print(response)

Metadata

Release files for llama-index-graph-stores-tidb 0.7.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 llama-index-graph-stores-tidb 0.7.0
File Size Uploaded Provenance Actions
llama_index_graph_stores_tidb-0.7.0.tar.gz 8.9 kB Without provenance Details for llama_index_graph_stores_tidb-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-graph-stores-tidb 0.7.0
File Interpreter ABI Platform Actions
llama_index_graph_stores_tidb-0.7.0-py3-none-any.whl Python 3 none any Details for llama_index_graph_stores_tidb-0.7.0-py3-none-any.whl

Total release size: 19.2 kB

Release files / llama_index_graph_stores_tidb-0.7.0.tar.gz

Download URL llama_index_graph_stores_tidb-0.7.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c0c23a9248bfa473be4ae54c6f41f0c6b2eaa604763fae49cf52e7c58db86d66
BLAKE2b-256 checksum
How to use checksums
48f8079f5959aca1b479fb7300ee6ff1bd9417d9352f335f55417f0c9f224f6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_graph_stores_tidb-0.7.0-py3-none-any.whl

Download URL llama_index_graph_stores_tidb-0.7.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d800c85cac3e7670531544f06437f61ef26d3e19ee077c4d13f80da3d0afb11
BLAKE2b-256 checksum
How to use checksums
7b13da4f851367f22314520807202f8bda1f3f32657f5c087f810fe740967fb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-graph-stores-tidb 0.7.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.

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