LightRAG/lightrag
anouarbm a934becfcc feat: add optional Langfuse observability integration
This contribution adds optional Langfuse support for LLM observability and tracing.
Langfuse provides a drop-in replacement for the OpenAI client that automatically
tracks all LLM interactions without requiring code changes.

Features:
- Optional Langfuse integration with graceful fallback
- Automatic LLM request/response tracing
- Token usage tracking
- Latency metrics
- Error tracking
- Zero code changes required for existing functionality

Implementation:
- Modified lightrag/llm/openai.py to conditionally use Langfuse's AsyncOpenAI
- Falls back to standard OpenAI client if Langfuse is not installed
- Logs observability status on import

Configuration:
To enable Langfuse tracing, install the observability extras and set environment variables:

```bash
pip install lightrag-hku[observability]

export LANGFUSE_PUBLIC_KEY="your_public_key"
export LANGFUSE_SECRET_KEY="your_secret_key"
export LANGFUSE_HOST="https://cloud.langfuse.com"  # or your self-hosted instance
```

If Langfuse is not installed or environment variables are not set, LightRAG
will use the standard OpenAI client without any functionality changes.

Changes:
- Modified lightrag/llm/openai.py (added optional Langfuse import)
- Updated pyproject.toml with optional 'observability' dependencies

Dependencies (optional):
- langfuse>=3.8.1

(cherry picked from commit 626b42bc40)
2025-12-04 19:11:08 +08:00
..
api fix(docs): correct typo "acivate" → "activate" 2025-12-04 19:11:08 +08:00
evaluation Restructure semaphore control to manage entire evaluation pipeline 2025-12-04 19:09:02 +08:00
kg Add retry decorators to Neo4j read operations for resilience 2025-12-04 19:09:08 +08:00
llm feat: add optional Langfuse observability integration 2025-12-04 19:11:08 +08:00
models tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
services tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
tools Improve LightRAG initialization checker tool with better usage docs 2025-12-04 19:09:05 +08:00
__init__.py Bump core version to 1.4.9.1 2025-09-28 15:25:02 +08:00
base.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
constants.py fix: sync core modules with upstream for compatibility 2025-12-04 19:10:46 +08:00
exceptions.py fix: sync core modules with upstream for compatibility 2025-12-04 19:10:46 +08:00
lightrag.py fix: sync core modules with upstream for compatibility 2025-12-04 19:10:46 +08:00
namespace.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
operate.py fix: sync core modules with upstream for compatibility 2025-12-04 19:10:46 +08:00
prompt.py Improve prompt clarity by standardizing terminology and formatting 2025-09-28 13:31:55 +08:00
rerank.py Improve edge case handling for max_tokens=1 2025-12-04 19:09:07 +08:00
security.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
tenant_rag_manager.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
types.py
utils.py Optimize JSON write with fast/slow path to reduce memory usage 2025-12-04 19:09:04 +08:00
utils_context.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
utils_graph.py Improve entity merge logging by removing redundant message and fixing typo 2025-12-04 19:09:02 +08:00