Skip to main content

LightRAG integration with Memgraph

Project description

🔗 lightrag-memgraph

lightrag-memgraph is an integration that connects lightrag and memgraph. The library began as a small wrapper designed to specifically configure Memgraph within a pipeline that processes unstructured data (various texts) and transforms it into an ontology/entity schema graph. In other words, it enables you to extract and enhance entities from unstructured documents, storing them in a graph for powerful querying and analysis. Ideal for building knowledge graphs, improving data discovery, and leveraging advanced AI techniques on top of your domain data.

General Notes

  • Entity/relationship extraction is high-quality, but also high-cost and relatively slow.
  • The goal over time is to expose time and cost metrics (e.g., $ per your specific document page or chunk).

Quick start

Prerequisites: Memgraph running *(default bolt://localhost:7687), and an LLM API key (e.g. OPENAI_API_KEY or *ANTHROPIC_API_KEY).

Install:

pip install lightrag-memgraph

Minimal example (async): create the wrapper, initialize with a working *directory, insert text, then finalize.

import asyncio
from lightrag_memgraph import MemgraphLightRAGWrapper

async def main():
    wrapper = MemgraphLightRAGWrapper(disable_embeddings=True)
    await wrapper.initialize(working_dir="./lightrag_storage")
    await wrapper.ainsert(input="Your document text here.", file_paths=["doc1"])
    # optional: rag = wrapper.get_lightrag(); print(await rag.get_graph_labels())
    await wrapper.afinalize()

asyncio.run(main())

See example.py in this repo for a full run with sample texts and graph output.

Using Anthropic (Claude) as the LLM

LightRAG supports Claude via the lightrag.llm.anthropic module. Set your API key and pass the LLM function and model name when initializing the wrapper. The list of Anthropic models is available under https://platform.claude.com/docs/en/about-claude/models.

  1. Set the API key (required for Claude):

    export ANTHROPIC_API_KEY="your-anthropic-api-key"
    
  2. Use Anthropic in code by passing llm_model_func and llm_model_name to initialize():

    from lightrag.llm.anthropic import anthropic_complete
    from lightrag_memgraph import MemgraphLightRAGWrapper
    
    wrapper = MemgraphLightRAGWrapper(disable_embeddings=True)  # or set embedding_func
    await wrapper.initialize(
        working_dir="./lightrag_storage",
        llm_model_func=anthropic_complete,
        llm_model_name="claude-3-5-sonnet-20241022",  # or claude-3-haiku-20240307, etc.
    )
    

    Preset functions are also available: claude_3_opus_complete, claude_3_sonnet_complete, claude_3_haiku_complete (fixed older model IDs). For current models, use anthropic_complete with the desired llm_model_name.

  3. Embeddings: Anthropic does not provide embeddings. Either use disable_embeddings=True (as above), or set embedding_func to another provider (e.g. openai_embed from lightrag.llm.openai with OPENAI_API_KEY, or Voyage AI via lightrag.llm.anthropic.anthropic_embed with VOYAGE_API_KEY).

Using OpenAI as the LLM

Set your API key and optionally choose a model.

  1. Set the API key:

    export OPENAI_API_KEY="your-openai-api-key"
    
  2. Use a specific OpenAI model by passing llm_model_func and optionally llm_model_name:

    from lightrag.llm.openai import gpt_4o_mini_complete, openai_embed
    from lightrag_memgraph import MemgraphLightRAGWrapper
    
    wrapper = MemgraphLightRAGWrapper()
    await wrapper.initialize(
        working_dir="./lightrag_storage",
        llm_model_func=gpt_4o_mini_complete,
        embedding_func=openai_embed,
    )
    

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

lightrag_memgraph-0.1.5.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

lightrag_memgraph-0.1.5-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file lightrag_memgraph-0.1.5.tar.gz.

File metadata

  • Download URL: lightrag_memgraph-0.1.5.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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 lightrag_memgraph-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9acaa94adcfb1b23438b89297b4e75f21dc376eb304e64d7f9f8d8d11f8dc51e
MD5 68b20a52c40a67f008c5e85bcc386713
BLAKE2b-256 7785b9cc705ea2037483579b6e75063a131e206b6418e52270b2438300068c2e

See more details on using hashes here.

File details

Details for the file lightrag_memgraph-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: lightrag_memgraph-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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 lightrag_memgraph-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c15c514994c44f92677878722a1d1c0701fc78998d7a310ed74b7602ad7df818
MD5 501c1ddb9dce915d05d6962d7b49094c
BLAKE2b-256 175d7fc5cd39e490a57d20f2f42762ce8a3b81b4fef9fff125fb9fc67e923640

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