llama-index-graph-stores-tidb


Namellama-index-graph-stores-tidb JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
Summaryllama-index graph stores tidb integration
upload_time2024-08-22 04:31:46
maintainerNone
docs_urlNone
authorYour Name
requires_python<4.0,>=3.8.1
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://tidb.cloud/ai).

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

```shell
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](https://tidb.cloud/ai).

Please checkout this [tutorial](https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/property_graph/property_graph_tidb.ipynb) to learn how to use `TiDBPropertyGraphStore` with LlamaIndex.

Simple example to use `TiDBPropertyGraphStore`:

```python
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](https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/index_structs/knowledge_graph/TiDBKGIndexDemo.ipynb) 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`:

```python
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)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "llama-index-graph-stores-tidb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8.1",
    "maintainer_email": null,
    "keywords": null,
    "author": "Your Name",
    "author_email": "you@example.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/85/43dcfc94fb40ce961c5ea2861e6f93114a66dd265df35d28ff1deb88e08b/llama_index_graph_stores_tidb-0.2.0.tar.gz",
    "platform": null,
    "description": "# LlamaIndex Graph Stores Integration: TiDB\n\nTiDB 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](https://tidb.cloud/ai).\n\nIn 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.\n\n- Property Graph Store: `TiDBPropertyGraphStore`\n- Knowledge Graph Store: `TiDBGraphStore`\n\n## Installation\n\n```shell\npip install llama-index llama-index-graph-stores-tidb\n```\n\n## Usage\n\n### Property Graph Store\n\nNOTE: `TiDBPropertyGraphStore` requires the Vector Search feature in TiDB, but now it is only available in [TiDB Cloud Serverless](https://tidb.cloud/ai).\n\nPlease checkout this [tutorial](https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/property_graph/property_graph_tidb.ipynb) to learn how to use `TiDBPropertyGraphStore` with LlamaIndex.\n\nSimple example to use `TiDBPropertyGraphStore`:\n\n```python\nfrom llama_index.core import PropertyGraphIndex, SimpleDirectoryReader\nfrom llama_index.embeddings.openai import OpenAIEmbedding\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.core.indices.property_graph import SchemaLLMPathExtractor\nfrom llama_index.graph_stores.tidb import TiDBPropertyGraphStore\n\ndocuments = SimpleDirectoryReader(\n    \"../../../examples/data/paul_graham/\"\n).load_data()\n\ngraph_store = TiDBPropertyGraphStore(\n    db_connection_string=\"mysql+pymysql://user:password@host:4000/dbname?ssl_verify_cert=true&ssl_verify_identity=true\",\n)\n\nindex = PropertyGraphIndex.from_documents(\n    documents,\n    embed_model=OpenAIEmbedding(model_name=\"text-embedding-3-small\"),\n    kg_extractors=[\n        SchemaLLMPathExtractor(\n            llm=OpenAI(model=\"gpt-3.5-turbo\", temperature=0.0)\n        )\n    ],\n    property_graph_store=graph_store,\n    show_progress=True,\n)\n\nquery_engine = index.as_query_engine(include_text=True)\nresponse = query_engine.query(\"What happened at Interleaf and Viaweb?\")\nprint(response)\n```\n\n### Knowledge Graph Store\n\nCheckout this [tutorial](https://github.com/run-llama/llama_index/blob/main/docs/docs/examples/index_structs/knowledge_graph/TiDBKGIndexDemo.ipynb) to learn how to use `TiDBGraphStore` with LlamaIndex.\n\nFor `TiDBGraphStore`, you can use either Self-Hosted TiDB or TiDB Cloud Serverless(Recommended).\n\nSimple example to use `TiDBGraphStore`:\n\n```python\nfrom llama_index.graph_stores.tidb import TiDBGraphStore\nfrom llama_index.core import (\n    KnowledgeGraphIndex,\n    SimpleDirectoryReader,\n    StorageContext,\n)\n\ndocuments = SimpleDirectoryReader(\n    \"../../../examples/data/paul_graham/\"\n).load_data()\n\ngraph_store = TiDBGraphStore(\n    db_connection_string=\"mysql+pymysql://user:password@host:4000/dbname\"\n)\nstorage_context = StorageContext.from_defaults(graph_store=graph_store)\nindex = KnowledgeGraphIndex.from_documents(\n    documents=documents,\n    storage_context=storage_context,\n    max_triplets_per_chunk=2,\n)\nquery_engine = index.as_query_engine(\n    include_text=False, response_mode=\"tree_summarize\"\n)\nresponse = query_engine.query(\n    \"Tell me more about Interleaf\",\n)\nprint(response)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "llama-index graph stores tidb integration",
    "version": "0.2.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79cd9c853a02511547c5742a4136f7a61c26f59fc18f5b79d877356eedb0139b",
                "md5": "77da93d618bdbab9b934206b09349a73",
                "sha256": "8422a7361037a0396049a6fe396122631d8a18617c52f58f151526b885624c77"
            },
            "downloads": -1,
            "filename": "llama_index_graph_stores_tidb-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "77da93d618bdbab9b934206b09349a73",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8.1",
            "size": 9472,
            "upload_time": "2024-08-22T04:31:45",
            "upload_time_iso_8601": "2024-08-22T04:31:45.607388Z",
            "url": "https://files.pythonhosted.org/packages/79/cd/9c853a02511547c5742a4136f7a61c26f59fc18f5b79d877356eedb0139b/llama_index_graph_stores_tidb-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f78543dcfc94fb40ce961c5ea2861e6f93114a66dd265df35d28ff1deb88e08b",
                "md5": "33fd4c60809bc7cc93d6df94aa5975d4",
                "sha256": "ec0683a13f55d289a02eaa771c444aee74941a71073a2d3fa13f23e2a995a8ea"
            },
            "downloads": -1,
            "filename": "llama_index_graph_stores_tidb-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "33fd4c60809bc7cc93d6df94aa5975d4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8.1",
            "size": 8542,
            "upload_time": "2024-08-22T04:31:46",
            "upload_time_iso_8601": "2024-08-22T04:31:46.476623Z",
            "url": "https://files.pythonhosted.org/packages/f7/85/43dcfc94fb40ce961c5ea2861e6f93114a66dd265df35d28ff1deb88e08b/llama_index_graph_stores_tidb-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-22 04:31:46",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "llama-index-graph-stores-tidb"
}
        
Elapsed time: 0.29491s