Skip to main content

llama-index graph stores tidb integration

Project description

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)

Project details


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.4.1.tar.gz (9.0 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.4.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_graph_stores_tidb-0.4.1.tar.gz
Algorithm Hash digest
SHA256 b817171606987aca44b5fb9b570416ceffee764e62e9b46f5f69d6f4ede95d4c
MD5 0604bb0b94bf56ebdc6d06b3a95b85a8
BLAKE2b-256 210a77ecf831b7a2f8c9d67bfc809f4c1dec1db21a11c8d8d4b659197804da5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_graph_stores_tidb-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3cd9f6374e3ec4f1632c54d64436c086f099070cb10d132c058465db71de6ba3
MD5 5499af4962c99d8fadb75699e5d572b2
BLAKE2b-256 ce154c33126d7a82a6998ab7b37dac94e8e9740467d10c278c2f4ffc0d9b2e21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page