llama-index-agensgraph


Namellama-index-agensgraph JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/skaiworldwide-oss/agensgraph-ai/tree/main/llama-index
Summaryllama-index graph and vector stores integration for agensgraph
upload_time2025-10-22 01:52:22
maintainerNone
docs_urlNone
authorMuhammad Taha Naveed
requires_python<4.0,>=3.9
licenseNone
keywords llama-index agensgraph graph store vector store integration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LlamaIndex AgensGraph

This plugin provides support for AgensGraphStore integration in [llamaindex](https://www.llamaindex.ai/), for persisting graphs directly in [AgensGraph](https://github.com/skaiworldwide-oss/agensgraph). Additionally, we support the PropertyGraphIndex and VectorStore, which allows you to store and query property graphs and vectors in AgensGraph.

- Property Graph Store: `AgensPropertyGraphStore`
- Knowledege Graph Store: `AgensGraphStore`
- Vector Store: `AgensgraphVectorStore`

See the associated guides below:

- [Agens Graph Store](./examples/index_structs/knowledge_graph/AgensgraphDemo.ipynb)
- [Agens Property Graph Store](./examples//property_graph/property_graph_agensgraph.ipynb)
- [Agensgraph Vector Store](./examples/vector_stores/AgensgraphVectorDemo.ipynb)


## Installation

```shell
pip install llama-index llama-index-agensgraph
```

## Usage

### Property Graph Store

```python
import os
import urllib.request
import nest_asyncio
from llama_index.core import SimpleDirectoryReader, PropertyGraphIndex
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_agensgraph.graph_stores.agensgraph import AgensPropertyGraphStore

os.environ[
    "OPENAI_API_KEY"
] = "<YOUR_API_KEY>"  # Replace with your OpenAI API key

os.makedirs("data/paul_graham/", exist_ok=True)

url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt"
output_path = "data/paul_graham/paul_graham_essay.txt"
urllib.request.urlretrieve(url, output_path)

nest_asyncio.apply()

with open(output_path, "r", encoding="utf-8") as file:
    content = file.read()

modified_content = content.replace("'", "\\'")

with open(output_path, "w", encoding="utf-8") as file:
    file.write(modified_content)

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

# Setup AgensGraph connection (ensure AgensGraph is running)
conf = {
    "dbname": "",
    "user": "",
    "password": "",
    "host": "",
    "port": "",
}

graph_store = AgensPropertyGraphStore(
    graph_name="graph",
    conf=conf
)

index = PropertyGraphIndex.from_documents(
    documents,
    embed_model=OpenAIEmbedding(model_name="text-embedding-ada-002"),
    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("\nDetailed Query Response:")
print(str(response))
```

### Knowledge Graph Store

```python
import os
import logging
from llama_index.llms.openai import OpenAI
from llama_index.core import Settings
from llama_index.core import (
    KnowledgeGraphIndex,
    SimpleDirectoryReader,
    StorageContext,
)
from llama_index_agensgraph.graph_stores.agensgraph import AgensGraphStore

os.environ[
    "OPENAI_API_KEY"
] = "<YOUR_API_KEY>"  # Replace with your OpenAI API key

logging.basicConfig(level=logging.INFO)

llm = OpenAI(temperature=0, model="gpt-3.5-turbo")
Settings.llm = llm
Settings.chunk_size = 512

documents = {
    "doc1.txt": "Python is a popular programming language known for its readability and simplicity. It was created by Guido van Rossum and first released in 1991. Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming. It is widely used in web development, data science, artificial intelligence, and scientific computing.",
    "doc2.txt": "JavaScript is a high-level programming language primarily used for web development. It was created by Brendan Eich and first appeared in 1995. JavaScript is a core technology of the World Wide Web, alongside HTML and CSS. It enables interactive web pages and is an essential part of web applications. JavaScript is also used in server-side development with environments like Node.js.",
    "doc3.txt": "Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It was developed by James Gosling and first released by Sun Microsystems in 1995. Java is widely used for building enterprise-scale applications, mobile applications, and large systems development.",
}

for filename, content in documents.items():
    with open(filename, "w") as file:
        file.write(content)

loaded_documents = SimpleDirectoryReader(".").load_data()

# Setup AgensGraph connection (ensure AgensGraph is running)
conf = {
    "dbname": "",
    "user": "",
    "password": "",
    "host": "",
    "port": "",
}

graph_store = AgensGraphStore(
    graph_name="graph",
    conf=conf
)

storage_context = StorageContext.from_defaults(graph_store=graph_store)

index = KnowledgeGraphIndex.from_documents(
    loaded_documents,
    storage_context=storage_context,
    max_triplets_per_chunk=3,
)

query_engine = index.as_query_engine(
    include_text=False, response_mode="tree_summarize"
)
response = query_engine.query("Tell me about Python and its uses")

print("Query Response:")
print(response)
```

### Vector Store
```python
import os
import urllib.request
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, StorageContext
from llama_index_agensgraph.vector_stores.agensgraph.base import AgensgraphVectorStore

# Set your OpenAI API key
os.environ["OPENAI_API_KEY"] = "<YOUR_API_KEY>"  # Replace with your key

# Download example data
os.makedirs("data/paul_graham/", exist_ok=True)
url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt"
output_path = "data/paul_graham/paul_graham_essay.txt"
urllib.request.urlretrieve(url, output_path)

# Load documents
documents = SimpleDirectoryReader("./data/paul_graham").load_data()

# Setup AgensGraph connection (ensure AgensGraph is running)
url = "postgresql://username:password@host:port/database_name"
embed_dim = 1536

# Initialize vector store
vector_store = AgensgraphVectorStore(url=url, embedding_dimension=embed_dim)

# Build index
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)

# Query
query_engine = index.as_query_engine()
response = query_engine.query("What happened at Interleaf?")
print("\nQuery Response:")
print(str(response))
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/skaiworldwide-oss/agensgraph-ai/tree/main/llama-index",
    "name": "llama-index-agensgraph",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "llama-index, agensgraph, graph store, vector store, integration",
    "author": "Muhammad Taha Naveed",
    "author_email": "skaisw@skaiworldwide.com",
    "download_url": "https://files.pythonhosted.org/packages/92/79/ceabc64ae5014deccf32187be4c2dee8d46e60789b50d05bede42eac166a/llama_index_agensgraph-0.1.0.tar.gz",
    "platform": null,
    "description": "# LlamaIndex AgensGraph\n\nThis plugin provides support for AgensGraphStore integration in [llamaindex](https://www.llamaindex.ai/), for persisting graphs directly in [AgensGraph](https://github.com/skaiworldwide-oss/agensgraph). Additionally, we support the PropertyGraphIndex and VectorStore, which allows you to store and query property graphs and vectors in AgensGraph.\n\n- Property Graph Store: `AgensPropertyGraphStore`\n- Knowledege Graph Store: `AgensGraphStore`\n- Vector Store: `AgensgraphVectorStore`\n\nSee the associated guides below:\n\n- [Agens Graph Store](./examples/index_structs/knowledge_graph/AgensgraphDemo.ipynb)\n- [Agens Property Graph Store](./examples//property_graph/property_graph_agensgraph.ipynb)\n- [Agensgraph Vector Store](./examples/vector_stores/AgensgraphVectorDemo.ipynb)\n\n\n## Installation\n\n```shell\npip install llama-index llama-index-agensgraph\n```\n\n## Usage\n\n### Property Graph Store\n\n```python\nimport os\nimport urllib.request\nimport nest_asyncio\nfrom llama_index.core import SimpleDirectoryReader, PropertyGraphIndex\nfrom llama_index.embeddings.openai import OpenAIEmbedding\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.core.indices.property_graph import SchemaLLMPathExtractor\n\nfrom llama_index_agensgraph.graph_stores.agensgraph import AgensPropertyGraphStore\n\nos.environ[\n    \"OPENAI_API_KEY\"\n] = \"<YOUR_API_KEY>\"  # Replace with your OpenAI API key\n\nos.makedirs(\"data/paul_graham/\", exist_ok=True)\n\nurl = \"https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt\"\noutput_path = \"data/paul_graham/paul_graham_essay.txt\"\nurllib.request.urlretrieve(url, output_path)\n\nnest_asyncio.apply()\n\nwith open(output_path, \"r\", encoding=\"utf-8\") as file:\n    content = file.read()\n\nmodified_content = content.replace(\"'\", \"\\\\'\")\n\nwith open(output_path, \"w\", encoding=\"utf-8\") as file:\n    file.write(modified_content)\n\ndocuments = SimpleDirectoryReader(\"./data/paul_graham/\").load_data()\n\n# Setup AgensGraph connection (ensure AgensGraph is running)\nconf = {\n    \"dbname\": \"\",\n    \"user\": \"\",\n    \"password\": \"\",\n    \"host\": \"\",\n    \"port\": \"\",\n}\n\ngraph_store = AgensPropertyGraphStore(\n    graph_name=\"graph\",\n    conf=conf\n)\n\nindex = PropertyGraphIndex.from_documents(\n    documents,\n    embed_model=OpenAIEmbedding(model_name=\"text-embedding-ada-002\"),\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)\n\nresponse = query_engine.query(\"What happened at Interleaf and Viaweb?\")\nprint(\"\\nDetailed Query Response:\")\nprint(str(response))\n```\n\n### Knowledge Graph Store\n\n```python\nimport os\nimport logging\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.core import Settings\nfrom llama_index.core import (\n    KnowledgeGraphIndex,\n    SimpleDirectoryReader,\n    StorageContext,\n)\nfrom llama_index_agensgraph.graph_stores.agensgraph import AgensGraphStore\n\nos.environ[\n    \"OPENAI_API_KEY\"\n] = \"<YOUR_API_KEY>\"  # Replace with your OpenAI API key\n\nlogging.basicConfig(level=logging.INFO)\n\nllm = OpenAI(temperature=0, model=\"gpt-3.5-turbo\")\nSettings.llm = llm\nSettings.chunk_size = 512\n\ndocuments = {\n    \"doc1.txt\": \"Python is a popular programming language known for its readability and simplicity. It was created by Guido van Rossum and first released in 1991. Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming. It is widely used in web development, data science, artificial intelligence, and scientific computing.\",\n    \"doc2.txt\": \"JavaScript is a high-level programming language primarily used for web development. It was created by Brendan Eich and first appeared in 1995. JavaScript is a core technology of the World Wide Web, alongside HTML and CSS. It enables interactive web pages and is an essential part of web applications. JavaScript is also used in server-side development with environments like Node.js.\",\n    \"doc3.txt\": \"Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It was developed by James Gosling and first released by Sun Microsystems in 1995. Java is widely used for building enterprise-scale applications, mobile applications, and large systems development.\",\n}\n\nfor filename, content in documents.items():\n    with open(filename, \"w\") as file:\n        file.write(content)\n\nloaded_documents = SimpleDirectoryReader(\".\").load_data()\n\n# Setup AgensGraph connection (ensure AgensGraph is running)\nconf = {\n    \"dbname\": \"\",\n    \"user\": \"\",\n    \"password\": \"\",\n    \"host\": \"\",\n    \"port\": \"\",\n}\n\ngraph_store = AgensGraphStore(\n    graph_name=\"graph\",\n    conf=conf\n)\n\nstorage_context = StorageContext.from_defaults(graph_store=graph_store)\n\nindex = KnowledgeGraphIndex.from_documents(\n    loaded_documents,\n    storage_context=storage_context,\n    max_triplets_per_chunk=3,\n)\n\nquery_engine = index.as_query_engine(\n    include_text=False, response_mode=\"tree_summarize\"\n)\nresponse = query_engine.query(\"Tell me about Python and its uses\")\n\nprint(\"Query Response:\")\nprint(response)\n```\n\n### Vector Store\n```python\nimport os\nimport urllib.request\nfrom llama_index.core import SimpleDirectoryReader, VectorStoreIndex, StorageContext\nfrom llama_index_agensgraph.vector_stores.agensgraph.base import AgensgraphVectorStore\n\n# Set your OpenAI API key\nos.environ[\"OPENAI_API_KEY\"] = \"<YOUR_API_KEY>\"  # Replace with your key\n\n# Download example data\nos.makedirs(\"data/paul_graham/\", exist_ok=True)\nurl = \"https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt\"\noutput_path = \"data/paul_graham/paul_graham_essay.txt\"\nurllib.request.urlretrieve(url, output_path)\n\n# Load documents\ndocuments = SimpleDirectoryReader(\"./data/paul_graham\").load_data()\n\n# Setup AgensGraph connection (ensure AgensGraph is running)\nurl = \"postgresql://username:password@host:port/database_name\"\nembed_dim = 1536\n\n# Initialize vector store\nvector_store = AgensgraphVectorStore(url=url, embedding_dimension=embed_dim)\n\n# Build index\nstorage_context = StorageContext.from_defaults(vector_store=vector_store)\nindex = VectorStoreIndex.from_documents(documents, storage_context=storage_context)\n\n# Query\nquery_engine = index.as_query_engine()\nresponse = query_engine.query(\"What happened at Interleaf?\")\nprint(\"\\nQuery Response:\")\nprint(str(response))\n```",
    "bugtrack_url": null,
    "license": null,
    "summary": "llama-index graph and vector stores integration for agensgraph",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/skaiworldwide-oss/agensgraph-ai/tree/main/llama-index",
        "Repository": "https://github.com/skaiworldwide-oss/agensgraph-ai/tree/main/llama-index"
    },
    "split_keywords": [
        "llama-index",
        " agensgraph",
        " graph store",
        " vector store",
        " integration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa877fa8964257400a2484f95ef7d758e28c944c94a5513c7bfef92384c56651",
                "md5": "e264489aa586ad9845dde587477e0d00",
                "sha256": "5b9be6943e71f4c1dfa59ae648da386492c5686f522bdeb8e403bf290b021f09"
            },
            "downloads": -1,
            "filename": "llama_index_agensgraph-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e264489aa586ad9845dde587477e0d00",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 30961,
            "upload_time": "2025-10-22T01:52:21",
            "upload_time_iso_8601": "2025-10-22T01:52:21.334871Z",
            "url": "https://files.pythonhosted.org/packages/fa/87/7fa8964257400a2484f95ef7d758e28c944c94a5513c7bfef92384c56651/llama_index_agensgraph-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9279ceabc64ae5014deccf32187be4c2dee8d46e60789b50d05bede42eac166a",
                "md5": "746020bdc41eca2dbac8efd84b5c1a22",
                "sha256": "1702c667cc4f8a5d769f4a387d95219842b4e8acbaaeae81d068bd7aed5c67a2"
            },
            "downloads": -1,
            "filename": "llama_index_agensgraph-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "746020bdc41eca2dbac8efd84b5c1a22",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 27431,
            "upload_time": "2025-10-22T01:52:22",
            "upload_time_iso_8601": "2025-10-22T01:52:22.495228Z",
            "url": "https://files.pythonhosted.org/packages/92/79/ceabc64ae5014deccf32187be4c2dee8d46e60789b50d05bede42eac166a/llama_index_agensgraph-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-22 01:52:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "skaiworldwide-oss",
    "github_project": "agensgraph-ai",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "llama-index-agensgraph"
}
        
Elapsed time: 1.38360s