Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1595ba8
Add Baseline + Graph RAG tools
gitbuda Aug 29, 2025
0d155c9
Add working LightRAG example
gitbuda Aug 29, 2025
78e79b2
Add evaluations
gitbuda Aug 30, 2025
197bdfe
Add information density dummy metric
gitbuda Aug 30, 2025
1e0cff3
Add unstructured test data
gitbuda Aug 31, 2025
135a0cf
Merge branch 'add-basic-rag-evaluations' into add-baseline-graph-rag-…
gitbuda Aug 31, 2025
d90467a
Add the uv structure
gitbuda Aug 31, 2025
c5138bf
Merge branch 'add-basic-rag-evaluations' into add-baseline-graph-rag-…
gitbuda Aug 31, 2025
45f716a
Add print evaluation summary
gitbuda Aug 31, 2025
88cd186
Merge branch 'add-basic-rag-evaluations' into add-baseline-graph-rag-…
gitbuda Aug 31, 2025
deea282
Run dummy evaluations on the kagglehub simple dataset
gitbuda Aug 31, 2025
5edd650
Merge branch 'main' into add-baseline-graph-rag-tools
gitbuda Sep 6, 2025
af2ec72
Add the new tools to the mcp server
gitbuda Sep 6, 2025
bfc9a15
Update the project version
gitbuda Sep 6, 2025
46fb5d9
Merge branch 'add-new-tools-to-the-mcp-server' into add-baseline-grap…
gitbuda Sep 6, 2025
0a88c9e
Add an attempt to make litellm + mcp client prompt lib (WIP/not_working)
gitbuda Sep 6, 2025
f7cd46d
Add the working version
gitbuda Sep 7, 2025
08cbc40
Make the StdioServerParams dynamically resolved
gitbuda Sep 7, 2025
4aeebe3
Add prompt-evals and mcp-prompt-lib as workspaces
gitbuda Sep 7, 2025
921aab1
Add evals to prompt evals
gitbuda Sep 7, 2025
c55e88f
Improve a bit on the calling MCP tools side
gitbuda Sep 8, 2025
244c516
Add the TODO parameters to run under hosted_vllm/openai/gpt-oss-20b
gitbuda Sep 8, 2025
9546a2e
Replace evaluations/ with DeepEval
gitbuda Sep 9, 2025
e6950c9
Add llm_model_resolver
gitbuda Sep 9, 2025
b757d9a
Fix the logger
gitbuda Sep 9, 2025
aa34f4f
Polish the prompt-evals CLI params
gitbuda Sep 10, 2025
34ebb10
Add more stuff to the model resolver because we are using different m…
gitbuda Sep 10, 2025
4556855
Add the hint prompt
gitbuda Sep 10, 2025
f8715d2
Resolve the asyncio calling issue (.run shoule be called once per pro…
gitbuda Sep 10, 2025
5ee0693
Add sentence embedding util
gitbuda Sep 13, 2025
144458a
Merge branch 'add-sentence-embedding-util' into add-baseline-graph-ra…
gitbuda Sep 14, 2025
e832af8
Try the prompt lib on another use-case
gitbuda Sep 14, 2025
e3c1693
Improve the prompt-lib in a way that MCP server params can be injected
gitbuda Sep 14, 2025
84ef68a
Fix the NodeVectorSearch tool call
gitbuda Sep 15, 2025
cc94d8a
Add experiments/entity-graph
gitbuda Sep 15, 2025
d048c59
Add lightrag to experiments
gitbuda Sep 16, 2025
45d16b1
Add configurable logging level to the memgraph-toolbox -> A NEW PR
gitbuda Sep 17, 2025
afe87b8
Add custom DeepEval Coherence metric
gitbuda Sep 17, 2025
7099300
Add logger to the mcp source file
gitbuda Sep 18, 2025
9ee6081
Try to plugin the HB model directly into LightRAG
gitbuda Sep 18, 2025
07b119a
Comment out the HB model
gitbuda Sep 18, 2025
8fd9698
Add MCP client prompt lib
gitbuda Sep 19, 2025
71acd5e
Add coherence embeddings-based DeepEval metric
gitbuda Sep 19, 2025
1ea365c
Remove parts that were move to a separated PRs
gitbuda Sep 19, 2025
679d94d
Merge the legit prompt lib
gitbuda Sep 19, 2025
795e0c1
Merge the legit coherence eval
gitbuda Sep 19, 2025
b280620
Remove the bitsandbytesbecause id doesn't work on mac
gitbuda Sep 19, 2025
1d55450
Remove the flash attention
gitbuda Sep 19, 2025
6657e5f
Polish and add tests
gitbuda Sep 20, 2025
2d98302
Fix the failing CI
gitbuda Sep 20, 2025
47dda21
Merge the embedding util
gitbuda Sep 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10
3.13
21 changes: 21 additions & 0 deletions experiments/csv-lib/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import csv
import argparse

parser = argparse.ArgumentParser(
description="Convert a text file to a CSV file with one line per row."
)
parser.add_argument("--txt", required=True, help="Path to the input text file.")
parser.add_argument("--csv", required=True, help="Path to the output CSV file.")
args = parser.parse_args()

txt_file_path = args.txt
csv_file_path = args.csv
with (
open(txt_file_path, "r", encoding="utf-8") as txt_file,
open(csv_file_path, "w", encoding="utf-8") as csv_file,
):
fieldnames = ["id", "prompt"]
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
for i, line in enumerate(txt_file):
writer.writerow({"id": i, "prompt": line.rstrip("\n")})
3 changes: 3 additions & 0 deletions experiments/entity-graph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files/
*.json
*.html
Empty file.
19 changes: 19 additions & 0 deletions experiments/entity-graph/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[llm]
model = "llama3.2"
api_key = ""
base_url = "http://localhost:11434/v1/chat/completions" # Local Ollama instance running locally (but can be any OpenAI compatible endpoint)
max_tokens = 8192
temperature = 0.2

[chunking]
chunk_size = 200 # Number of words per chunk
overlap = 20 # Number of words to overlap between chunks

[standardization]
enabled = true # Enable entity standardization
use_llm_for_entities = true # Use LLM for additional entity resolution

[inference]
enabled = true # Enable relationship inference
use_llm_for_inference = true # Use LLM for relationship inference
apply_transitive = true # Apply transitive inference rules
12 changes: 12 additions & 0 deletions experiments/entity-graph/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "entity-graph"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"ai-knowledge-graph",
]

[tool.uv.sources]
ai-knowledge-graph = { git = "https://github.com/robert-mcdermott/ai-knowledge-graph.git" }
3 changes: 3 additions & 0 deletions experiments/lightrag/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rag_storage/
example_storage/
lightrag_storage/
163 changes: 163 additions & 0 deletions experiments/lightrag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# LightRAG Memgraph Integration

A Python library that integrates LightRAG with Memgraph for knowledge graph-based Retrieval-Augmented Generation (RAG).

## Features

- **Knowledge Graph Storage**: Uses Memgraph as the graph storage backend for LightRAG
- **Multiple Search Modes**: Supports both naive and hybrid search strategies
- **Async Support**: Fully asynchronous API for better performance
- **Easy Integration**: Simple interface for text insertion and querying

## Installation

This library requires Python 3.8 or higher and uses uv for dependency management.

```bash
# Install the library
uv add lightrag-memgraph

# Or install in development mode
uv pip install -e .
```

## Dependencies

- `lightrag-hku[api]` - Core LightRAG functionality
- `openai` - OpenAI API integration for embeddings and LLM

## Usage

### Basic Setup

```python
import asyncio
from lightrag_memgraph import initialize_lightrag_memgraph

async def main():
# Initialize LightRAG with Memgraph storage
rag = await initialize_lightrag_memgraph(working_dir="./my_rag_storage")

# Insert some text
await rag.insert_text("Your document content here...")

# Query the knowledge graph
result = await rag.query_hybrid("What is this document about?")
print(result)

asyncio.run(main())
```

### Using the Class Directly

```python
import asyncio
from lightrag_memgraph import LightRAGMemgraph

async def main():
# Create instance
rag = LightRAGMemgraph(working_dir="./my_rag_storage", log_level="INFO")

# Initialize
await rag.initialize()

# Insert text
await rag.insert_text("Document content...")

# Search
naive_result = await rag.query_naive("Simple query")
hybrid_result = await rag.query_hybrid("Complex query")

print(f"Naive: {naive_result}")
print(f"Hybrid: {hybrid_result}")

asyncio.run(main())
```

### Using Convenience Functions

```python
import asyncio
from lightrag_memgraph import initialize_lightrag_memgraph, naive_search, hybrid_search, insert_text

async def main():
rag = await initialize_lightrag_memgraph()

# Insert text
await insert_text(rag, "Your content here...")

# Search using convenience functions
result1 = await naive_search(rag, "Query 1")
result2 = await hybrid_search(rag, "Query 2")

asyncio.run(main())
```

## Configuration

### Environment Variables

Make sure to set your OpenAI API key and Memgraph connection details:

```bash
export OPENAI_API_KEY="your-api-key-here"
export MEMGRAPH_URI="bolt://localhost:7687"
```

### Memgraph Configuration

The library uses Memgraph as the graph storage backend. Ensure you have a Memgraph instance running and accessible. The connection details are configured through environment variables:

- `MEMGRAPH_URI`: Memgraph connection URI (default: `bolt://localhost:7687`)
- `MEMGRAPH_USER`: Memgraph username (optional)
- `MEMGRAPH_PASSWORD`: Memgraph password (optional)

## Development

### Setup Development Environment

```bash
# Install development dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/
isort src/

# Type checking
mypy src/
```

## API Reference

### LightRAGMemgraph

Main class for LightRAG with Memgraph integration.

#### Methods

- `__init__(working_dir: str, log_level: str)`: Initialize the instance
- `initialize()`: Initialize LightRAG with Memgraph storage
- `query_naive(query: str)`: Perform naive search
- `query_hybrid(query: str)`: Perform hybrid search
- `insert_text(text: str)`: Insert text into the knowledge graph

### Convenience Functions

- `initialize_lightrag_memgraph(working_dir: str)`: Initialize and return a ready-to-use instance
- `naive_search(rag, query: str)`: Perform naive search
- `hybrid_search(rag, query: str)`: Perform hybrid search
- `insert_text(rag, text: str)`: Insert text

## Notes

- This is an experimental integration and may have limitations
- MemgraphStorage configuration may need to be adjusted based on your Memgraph setup
- Both `initialize_storages()` and `initialize_pipeline_status()` are called automatically during initialization

## License

This project is part of the Memgraph AI Toolkit.
22 changes: 22 additions & 0 deletions experiments/lightrag/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
"""Example usage of LightRAG Memgraph integration."""

import asyncio
from lightrag_memgraph import initialize_lightrag_memgraph


async def main():
"""Example main function demonstrating LightRAG Memgraph usage."""
print("Memgraph LightRAG Wrapper")

# Initialize LightRAG with Memgraph storage
rag = await initialize_lightrag_memgraph(working_dir="./lightrag_storage")

# Example usage (uncomment to test):
await rag.insert_text("This is a sample document about artificial intelligence.")
result = await rag.query_hybrid("What is this document about?")
print(f"Query result: {result}")


if __name__ == "__main__":
asyncio.run(main())
50 changes: 50 additions & 0 deletions experiments/lightrag/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[project]
name = "lightrag-memgraph"
version = "0.1.18"
description = "LightRAG integration with Memgraph for knowledge graph-based RAG"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
# "lightrag-hku[api] @ file:///home/buda/Workspace/tmp/LightRAG",
"lightrag-hku[api]>=0.0.1",
"openai>=1.0.0",
"neo4j>=5.0.0",
"accelerate>=1.10.1",
"torch>=2.8.0",
"transformers<=4.48.3",
# "flash-attn>=2.8.3", # NOTE: It causes a lot of issue because explicit torch deps requried.
# "bitsandbytes>=0.47.0", # NOTE: Doesn't work on Mac
]

[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"pytest-asyncio>=0.21.0",
"black>=23.0.0",
"isort>=5.12.0",
"mypy>=1.0.0",
]

[tool.uv.extra-build-dependencies]
flash-attn = ["torch"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/lightrag_memgraph"]

[tool.black]
line-length = 88
target-version = ['py310']

[tool.isort]
profile = "black"
line_length = 88

[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
14 changes: 14 additions & 0 deletions experiments/lightrag/src/lightrag_memgraph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""LightRAG integration with Memgraph for knowledge graph-based RAG."""

from .core import LightRAGMemgraph, initialize_lightrag_memgraph
from .search import naive_search, hybrid_search
from .insert import insert_text

__version__ = "0.1.0"
__all__ = [
"LightRAGMemgraph",
"initialize_lightrag_memgraph",
"naive_search",
"hybrid_search",
"insert_text",
]
Loading
Loading