GenAI library for RAG , MCP and Agentic AI
Project description
🔥 phoenix_ai
phoenix_ai is a modular Python library designed for GenAI tasks like--:
- 🔍 Vector embedding with FAISS
- 🤖 RAG Inference (Standard / Hybrid / HyDE)
- 📄 Ground truth Q&A generation from documents
- 🧪 Answer evaluation using BLEU + LLM-as-a-Judge (ChatGPT or Claude)
- 📊 MLflow logging of evaluation metrics
Supports:
🧠 OpenAI | ☁️ Azure OpenAI | 💼 Databricks Model Serving
📦 Installation
git clone https://github.com/your-org/phoenix_ai.git
cd phoenix_ai
poetry install
# 🔥 phoenix_ai
A modular Python library for building Generative AI applications using RAG (Retrieval-Augmented Generation), evaluation datasets, and LLM-as-a-Judge scoring. Supports OpenAI, Azure OpenAI, and Databricks.
---
## ⚙️ 1. Configure Embedding & Chat Clients
Supports `openai`, `azure-openai`, and `databricks` as providers.
### ▶️ OpenAI
```python
from phoenix_ai.utils import GenAIEmbeddingClient, GenAIChatClient
embedding_client = GenAIEmbeddingClient(
provider="openai",
model="text-embedding-ada-002",
api_key="your-openai-key"
)
chat_client = GenAIChatClient(
provider="openai",
model="gpt-4",
api_key="your-openai-key"
)
☁️ Azure OpenAI
embedding_client = GenAIEmbeddingClient(
provider="azure-openai",
model="text-embedding-ada-002",
api_key="your-azure-key",
api_version="2024-06-01",
azure_endpoint="https://<your-endpoint>.openai.azure.com"
)
chat_client = GenAIChatClient(
provider="azure-openai",
model="gpt-4",
api_key="your-azure-key",
api_version="2024-06-01",
azure_endpoint="https://<your-endpoint>.openai.azure.com"
)
embedding_client = GenAIEmbeddingClient(
provider="databricks",
model="bge_large_en_v1_5",
base_url="https://<your-databricks-url>",
api_key="your-databricks-token"
)
chat_client = GenAIChatClient(
provider="databricks",
model="databricks-claude-3-7-sonnet",
base_url="https://<your-databricks-url>",
api_key="your-databricks-token"
)
📂 2. Load and Process Documents
from phoenix_ai.loaders import load_and_process_single_document
df = load_and_process_single_document(folder_path="data/", filename="policy_doc.pdf")
📌 3. Generate FAISS Vector Index
from phoenix_ai.vector_embedding_pipeline import VectorEmbedding
vector = VectorEmbedding(embedding_client,chunk_size=500,overlap=50)
index_path, chunks = vector.generate_index(
df=df,
text_column="content",
index_path="output/policy_doc.index",
vector_index_type='local_index'
)
💬 4. Perform RAG Inference (Standard, Hybrid, HyDE)
from phoenix_ai.rag_inference import RAGInferencer
from phoenix_ai.param import Param
rag_inferencer = RAGInferencer(embedding_client, chat_client)
response_df = rag_inferencer.infer(
system_prompt=Param.get_rag_prompt(),
index_path="output/policy_doc.index",
question="What is the purpose of the company Group Data Classification Policy?",
mode="standard", # or "hybrid", "hyde"
top_k=5
)
🧪 5. Generate Ground Truth Q&A from Document
from phoenix_ai.eval_dataset_prep_ground_truth import EvalDatasetGroundTruthGenerator
generator = EvalDatasetGroundTruthGenerator(chat_client)
qa_df = generator.process_dataframe(
df=df,
text_column="content",
prompt_template=Param.get_ground_truth_prompt(),
max_total_pairs=50
)
qa_df.to_csv("output/eval_dataset_ground_truth.csv", index=False)
🔁 6. Apply RAG to Ground Truth Questions
from phoenix_ai.rag_evaluation_data_prep import RagEvalDataPrep
rag_data = RagEvalDataPrep(
inferencer=rag_inferencer,
system_prompt=Param.get_rag_prompt(),
index_type="local_index",
index_path="output/policy_doc.index"
)
result_df = rag_data.run_rag(input_df=qa_df, limit=5)
result_df.to_csv("output/eval_dataset_rag_output.csv", index=False)
📊 7. Evaluate RAG Output with LLM-as-a-Judge
from phoenix_ai.rag_eval import RagEvaluator
evaluator = RagEvaluator(chat_client, experiment_name="/Users/yourname/LLM_Answer_Evaluation")
df_input = result_df
df_eval, metrics = evaluator.evaluate(
input_df=df_input,
prompt=Param.get_evaluation_prompt(),
max_rows=5
)
df_eval.to_csv("output/eval_dataset_rag_eval.csv", index=False)
# Print metrics
for k, v in metrics.items():
print(f"{k}: {v:.4f}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
phoenix_ai-0.2.8.0.tar.gz
(14.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phoenix_ai-0.2.8.0.tar.gz.
File metadata
- Download URL: phoenix_ai-0.2.8.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60ac116a1d02439e4062a1739e438abd5dd4e40c87f4c469944f74a963ad09ff
|
|
| MD5 |
2fa2ea34cec3862433cfbbb49a74647e
|
|
| BLAKE2b-256 |
8ef9ffb49c02bf620930d96d6a1eed4e074e771baa7418f1f1cb1dca8ea71981
|
File details
Details for the file phoenix_ai-0.2.8.0-py3-none-any.whl.
File metadata
- Download URL: phoenix_ai-0.2.8.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58c19b2ab3bc628454c5ad9845e7d832007069f8ea917518a153c9e8bbda56f4
|
|
| MD5 |
b25f8abb5038baacb232e8cf15f9ceb5
|
|
| BLAKE2b-256 |
6ec9acd6da83809eb3cab38007b4cb7593c5d04a352553a8dc3c804a3bf25bd0
|