Skip to main content

llama-index Ladybug graph store integration

Project description

llama-index-ladybug

LlamaIndex graph store integration for Ladybug — an embedded graph database built for query speed and scalability. Ladybug is optimized for handling complex analytical workloads on very large databases and provides a set of retrieval features, such as full text search and vector indices.

The database was formerly known as Kùzu.

Installation

uv pip install llama-index-graph-stores-ladybug

Quick Start

LadybugPropertyGraphStore — unstructured (default)

No schema required. All LLM-extracted entities are stored as Entity type and only relation types are Links and Mentions.

from pathlib import Path
import real_ladybug as lb
from llama_index.graph_stores.ladybug import LadybugPropertyGraphStore
from llama_index.core import PropertyGraphIndex, SimpleDirectoryReader
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI

# Create a Ladybug database
Path("my_graph.ladybug").unlink(missing_ok=True)
db = lb.Database("my_graph.ladybug")

embed_model = OpenAIEmbedding(model_name="text-embedding-3-small")

graph_store = LadybugPropertyGraphStore(
    db,
    use_vector_index=True,
    embed_model=embed_model,
)

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

index = PropertyGraphIndex.from_documents(
    documents,
    embed_model=embed_model,
    property_graph_store=graph_store,
    show_progress=True,
)

query_engine = index.as_query_engine()
response = query_engine.query("What are the main topics in these documents?")
print(response)

LadybugPropertyGraphStore — structured schema

Pass a relationship_schema to guide the LLM towards your schema.

strict_schema=False (default) allows the graph to expand beyond the declared types — off-schema entities and relations are stored in overflow tables alongside the schema-defined ones.

strict_schema=True enforces the schema strictly — off-schema entities and relations are silently dropped at ingest.

graph_store = LadybugPropertyGraphStore(
    db,
    relationship_schema=[
        ("PERSON", "WORKS_FOR", "ORGANIZATION"),
        ("PERSON", "KNOWS", "PERSON"),
    ],
    has_structured_schema=True,
    strict_schema=False,   # True to reject off-schema types entirely
    use_vector_index=True,
    embed_model=embed_model,
)

LadybugGraphStore

import real_ladybug as lb
from llama_index.graph_stores.ladybug import LadybugGraphStore
from llama_index.core import KnowledgeGraphIndex, StorageContext, SimpleDirectoryReader

db = lb.Database("my_graph.ladybug")
graph_store = LadybugGraphStore(db)
storage_context = StorageContext.from_defaults(graph_store=graph_store)

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

index = KnowledgeGraphIndex.from_documents(
    documents,
    max_triplets_per_chunk=2,
    storage_context=storage_context,
)

query_engine = index.as_query_engine()
response = query_engine.query("What are the main topics in these documents?")
print(response)

Features

  • Embedded — no server required; the database is a local directory
  • Cypher queries — full Cypher support via structured_query()
  • Vector index — HNSW vector index on chunk nodes for similarity search, built into the graph store
  • Structured schemas — optionally enforce entity/relation types for higher-quality triple extraction
  • Both graph store APIs — supports both PropertyGraphIndex (LadybugPropertyGraphStore) and the legacy KnowledgeGraphIndex (LadybugGraphStore)

Documentation

Development

# Clone and set up
git clone https://github.com/stevereiner/llama-index-ladybug
cd llama-index-ladybug
uv sync --group dev

# Run tests
pytest

# Install pre-commit hooks (strips notebook outputs on commit)
pre-commit install

Requirements

  • Python 3.9+
  • real-ladybug >= 0.15.3
  • llama-index-core >= 0.13.0

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_ladybug-0.3.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file llama_index_graph_stores_ladybug-0.3.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_graph_stores_ladybug-0.3.0.tar.gz
Algorithm Hash digest
SHA256 be5f835d12a0af50f3632bf93a2b8d5411fbf1c2f2e18b49f3ef39d208085ef6
MD5 2c9bc4e8f6ea8fe6861f61813411b230
BLAKE2b-256 7e6bc90d6dde75f81aeae85feeb23b94e4e6c1586edf8f690050086af7e5f35e

See more details on using hashes here.

File details

Details for the file llama_index_graph_stores_ladybug-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_graph_stores_ladybug-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c3577b4fb5d0dbf5c5764695bba9a310ac5a19a945df2c120bf7ed01dd43fd5
MD5 6848217095f20fb66a454ac0a41c9fce
BLAKE2b-256 cc5afd33ebba7e41fbe8304fb67a9ceb555d4513e485fd4159f20740b79b2f68

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