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)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_graph_stores_tidb-0.6.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_graph_stores_tidb-0.6.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_graph_stores_tidb-0.6.0.tar.gz.

File metadata

  • Download URL: llama_index_graph_stores_tidb-0.6.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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

Hashes for llama_index_graph_stores_tidb-0.6.0.tar.gz
Algorithm Hash digest
SHA256 201da5fbdcecca34224df261a8b8d211b0f3fc97365dd7759651977bf6724d3e
MD5 80e516ec23e328779ed87979b1afbb88
BLAKE2b-256 6bfa5fd7a9c7949cf2bd827384ca3975deb8e205551cfbfb85b7cbaf5cca8764

See more details on using hashes here.

File details

Details for the file llama_index_graph_stores_tidb-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_graph_stores_tidb-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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

Hashes for llama_index_graph_stores_tidb-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29ead5e86b1e679e73f2f758f8fb362a04334cd50074a3f7c60955e6c25059d2
MD5 4375ec91f113b50bf25a440300353edc
BLAKE2b-256 9c9983caf80057b187203facdd6a1a3c6f24caee99511925ad0fa94050a7dff5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 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