Skip to content

Commit 9dc98ea

Browse files
DavIvekmatea16
andauthored
Add LightRAG to integrations page (#1338)
* add lightRAG to integrations page * minor fixes * Apply suggestions from code review * list lightrag in main page --------- Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> Co-authored-by: matea16 <mateapesic@hotmail.com>
1 parent 0c3249f commit 9dc98ea

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

pages/ai-ecosystem.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This section of Memgraph’s documentation is your guide to using Memgraph for A
2424
integrations with popular AI frameworks to help you customize and build your
2525
own GenAI application from scratch. Some of the libraries that support
2626
Memgraph include **Model Context Protocol (MCP)**, **LangChain**,
27-
**LlamaIndex**, **Cognee** and **Mem0**.
27+
**LlamaIndex**, **Cognee**, **Mem0** and **LightRAG**.
2828
- [Machine learning with Memgraph](/ai-ecosystem/machine-learning): Learn how
2929
Memgraph powers ML workflows with graph-powered insights.
3030
- [GraphChat in Memgraph Lab](/memgraph-lab/features/graphchat): Explore how

pages/ai-ecosystem/integrations.mdx

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Memgraph's officially supported integrations:
1616
- [LangChain](#langchain)
1717
- [Cognee](#cognee)
1818
- [Mem0](#mem0)
19+
- [LightRAG](#lightrag)
1920

2021

2122
## Model Context Protocol (MCP)
@@ -910,6 +911,142 @@ the official [Mem0
910911
docs](https://docs.mem0.ai/open-source/graph_memory/overview#initialize-memgraph).
911912

912913

914+
## LightRAG
915+
916+
<SocialCards>
917+
<SocialCard
918+
icon={<GitHub />}
919+
title="LightRAG integration"
920+
href="https://github.com/HKUDS/LightRAG"
921+
is_external={true}
922+
/>
923+
</SocialCards>
924+
925+
LightRAG is a simple and fast retrieval-augmented generation framework that
926+
combines the power of graph databases with large language models. It provides
927+
efficient graph-based knowledge representation and retrieval capabilities,
928+
making it ideal for building RAG applications that require sophisticated
929+
understanding of entity relationships and context.
930+
931+
LightRAG supports [Memgraph as a graph storage
932+
backend](https://github.com/HKUDS/LightRAG/blob/main/lightrag/kg/memgraph_impl.py),
933+
offering high-performance in-memory graph operations with full compatibility
934+
with the Neo4j Bolt protocol.
935+
936+
{<h3 className="custom-header">Installation</h3>}
937+
938+
To use LightRAG with Memgraph, you need to install LightRAG from source since
939+
Memgraph support is not yet available in the PyPI release:
940+
941+
```shell
942+
# Clone the LightRAG repository
943+
git clone https://github.com/HKUDS/LightRAG.git
944+
cd LightRAG
945+
946+
# Install from source
947+
pip install -e .
948+
```
949+
950+
{<h3 className="custom-header">Environment setup</h3>}
951+
952+
Before getting started, ensure you have [Memgraph](/getting-started) running.
953+
You can quickly start Memgraph using Docker:
954+
955+
```bash
956+
docker run -p 7687:7687 memgraph/memgraph:latest
957+
```
958+
959+
Configure your environment variables for Memgraph connection:
960+
961+
```bash
962+
export MEMGRAPH_URI="bolt://localhost:7687"
963+
export MEMGRAPH_USERNAME="" # Default is empty
964+
export MEMGRAPH_PASSWORD="" # Default is empty
965+
export MEMGRAPH_DATABASE="memgraph" # Default database name
966+
```
967+
968+
{<h3 className="custom-header">Basic usage</h3>}
969+
970+
Here's a simple example of using LightRAG with Memgraph:
971+
972+
Export your `OPENAI_API_KEY` environment variable before running the script.
973+
974+
```python
975+
import os
976+
import asyncio
977+
from lightrag import LightRAG, QueryParam
978+
from lightrag.llm.openai import gpt_4o_mini_complete, gpt_4o_complete, openai_embed
979+
from lightrag.kg.shared_storage import initialize_pipeline_status
980+
from lightrag.utils import setup_logger
981+
982+
setup_logger("lightrag", level="INFO")
983+
984+
WORKING_DIR = "./rag_storage"
985+
if not os.path.exists(WORKING_DIR):
986+
os.mkdir(WORKING_DIR)
987+
988+
async def initialize_rag():
989+
rag = LightRAG(
990+
working_dir=WORKING_DIR,
991+
embedding_func=openai_embed,
992+
llm_model_func=gpt_4o_mini_complete,
993+
graph_storage="MemgraphStorage", #<-----------override KG default
994+
)
995+
# IMPORTANT: Both initialization calls are required!
996+
await rag.initialize_storages() # Initialize storage backends
997+
await initialize_pipeline_status() # Initialize processing pipeline
998+
return rag
999+
1000+
async def main():
1001+
try:
1002+
# Initialize RAG instance
1003+
rag = await initialize_rag()
1004+
rag.insert("Your text")
1005+
1006+
# Perform hybrid search
1007+
mode = "hybrid"
1008+
print(
1009+
await rag.query(
1010+
"What are the top themes in this story?",
1011+
param=QueryParam(mode=mode)
1012+
)
1013+
)
1014+
1015+
except Exception as e:
1016+
print(f"An error occurred: {e}")
1017+
finally:
1018+
if rag:
1019+
await rag.finalize_storages()
1020+
1021+
if __name__ == "__main__":
1022+
asyncio.run(main())
1023+
```
1024+
1025+
{<h3 className="custom-header">Advanced configuration</h3>}
1026+
1027+
LightRAG provides several configuration options for working with Memgraph:
1028+
1029+
**Workspace isolation**: Use the `MEMGRAPH_WORKSPACE` environment variable to
1030+
isolate data between different LightRAG instances:
1031+
1032+
```bash
1033+
export MEMGRAPH_WORKSPACE="project_a"
1034+
```
1035+
1036+
**Custom connection parameters**: You can also configure connection parameters
1037+
through a `config.ini` file:
1038+
1039+
```ini
1040+
[memgraph]
1041+
uri = bolt://localhost:7687
1042+
username =
1043+
password =
1044+
database = memgraph
1045+
```
1046+
1047+
For more information about LightRAG's advanced configurations, features, and
1048+
usage examples with Memgraph, visit the [LightRAG GitHub
1049+
repository](https://github.com/HKUDS/LightRAG).
9131050

9141051

9151052
<CommunityLinks/>

0 commit comments

Comments
 (0)