Skip to main content

unstructured2graph

Convert unstructured documents into knowledge graphs within Memgraph.

Overview

unstructured2graph enables you to transform any unstructured data (PDFs, URLs, documents) into a graph database, powering Graph Retrieval-Augmented Generation (GraphRAG) applications. It combines:

  • Unstructured - Parse and chunk diverse document formats
  • LightRAG - Extract entities and relationships using LLMs
  • Memgraph - Store and query your knowledge graph

Installation

Install from source:

git clone https://github.com/memgraph/ai-toolkit.git
cd ai-toolkit/unstructured2graph
pip install -e .

For full document support (PDF, DOCX, etc.):

pip install -e ".[all-docs]"

Quick Start

import asyncio
from memgraph_toolbox.api.memgraph import Memgraph
from lightrag_memgraph import MemgraphLightRAGWrapper
from unstructured2graph import from_unstructured, create_property_index


async def main():
    memgraph = Memgraph(user_agent="unstructured2graph")
    create_property_index(memgraph, "Chunk", "hash")

    lightrag = MemgraphLightRAGWrapper()
    await lightrag.initialize(working_dir="./lightrag_storage")

    # Ingest documents from URLs or local files
    await from_unstructured(
        sources=["https://example.com/doc.pdf", "./local_file.md"],
        memgraph=memgraph,
        lightrag_wrapper=lightrag,
        link_chunks=True,  # Create NEXT relationships between chunks
    )
    await lightrag.afinalize()


asyncio.run(main())

Persistence: MemgraphLightRAGWrapper now persists LightRAG's full working state into Memgraph by default — the entity/relationship graph plus the key/value store, vector store, and document-status store. The working_dir argument is still accepted (and used as a fallback location for any store not backed by Memgraph), but with the default settings the JSON stores are no longer written there. See the lightrag-memgraph README for the label/index schema and opt-out flags.

Key Features

Feature Description
Multi-format parsing PDFs, URLs, HTML, Markdown, DOCX, and more via Unstructured
Automatic chunking Smart document chunking with configurable options
Entity extraction LLM-powered entity and relationship extraction via LightRAG
Vector search Built-in support for embedding generation and vector indices
GraphRAG queries Combine vector search with graph traversal for enhanced retrieval

API Reference

Document Processing

  • parse_source(source, partition_kwargs) - Parse a single file or URL into chunks
  • parse_text(text, partition_kwargs) - Chunk a raw in-memory string (no file/URL involved)
  • make_chunks(sources, partition_kwargs) - Process multiple sources into ChunkedDocument objects
  • from_unstructured(sources, memgraph, lightrag_wrapper, ...) - Full ingestion pipeline for files/URLs; returns one Chunk group per source
  • from_texts(texts, memgraph, lightrag_wrapper, ...) - Full ingestion pipeline for raw strings; returns one Chunk group per input text

Graph Operations

  • create_nodes_from_list(memgraph, nodes, label, batch_size) - Batch insert nodes
  • connect_chunks_to_entities(memgraph, chunk_label, entity_label) - Link entities to source chunks
  • link_nodes_in_order(memgraph, ...) - Create sequential relationships between chunks
  • create_vector_search_index(memgraph, label, property) - Create vector index for similarity search
  • compute_embeddings(memgraph, label) - Generate embeddings for nodes

Documentation

For detailed usage examples and getting started guides, check out the official documentation:

👉 unstructured2graph Documentation

Requirements

  • Python 3.10+
  • Memgraph database instance

LLM API Key

This library uses LightRAG for entity and relationship extraction, which requires an LLM API key. Set your OpenAI API key as an environment variable:

export OPENAI_API_KEY="your-api-key"

Download files

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

Source Distribution

unstructured2graph-0.4.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

unstructured2graph-0.4.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file unstructured2graph-0.4.0.tar.gz.

File metadata

  • Download URL: unstructured2graph-0.4.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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 unstructured2graph-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0a7d1912e22fb233f63f258356ac1b825e15af1d435dceffc7fecb42870221ab
MD5 aaebc8e18982842985b86dfe1d424e0d
BLAKE2b-256 a6a787324f728ceb9cf53ff175109fc9225e0603996d3c4040cd4642bbb68c0c

See more details on using hashes here.

File details

Details for the file unstructured2graph-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: unstructured2graph-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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 unstructured2graph-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25d96d3b162e0b4e5649825cf494db7d8898b118cf55d5410e0a41c58f38b4f2
MD5 c06b1eea6c260f0985a3f5586ce36955
BLAKE2b-256 763d4a47d8d5c14a454c2ff6643fc94e20c8237705cf8fb874e2f80ef8b7826c

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 Sentry Error logging StatusPage Status page