Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

fix(hyde_rag): remove unresolved merge conflict markers

Rudy Celekli760d0ca6f093
diff --git a/rag_apps/hyde_rag/.env.example b/rag_apps/hyde_rag/.env.example
index 2401cea..2348918 100644
--- a/rag_apps/hyde_rag/.env.example
+++ b/rag_apps/hyde_rag/.env.example
@@ -1,6 +1,3 @@
-<<<<<<< HEAD
-=======
# Google API key used to authenticate Gemini 3 Flash and Gemini Embedding 2 requests.
# Get one free at https://aistudio.google.com
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
GOOGLE_API_KEY=your_google_api_key_here
diff --git a/rag_apps/hyde_rag/app.py b/rag_apps/hyde_rag/app.py
index 36331b9..25e6cc5 100644
--- a/rag_apps/hyde_rag/app.py
+++ b/rag_apps/hyde_rag/app.py
@@ -1,9 +1,5 @@
"""
-<<<<<<< HEAD
-HyDE RAG — Gradio UI
-=======
HyDE RAG, Gradio UI
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
"""
import os
@@ -21,10 +17,7 @@ pipeline: HyDERAG | None = None
def get_or_create_pipeline(google_key: str) -> HyDERAG:
-<<<<<<< HEAD
-=======
"""Return the existing pipeline, creating one with the given key if none exists yet."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
global pipeline
if pipeline is None:
pipeline = HyDERAG(google_api_key=google_key)
@@ -34,20 +27,14 @@ def get_or_create_pipeline(google_key: str) -> HyDERAG:
# ── Handlers ───────────────────────────────────────────────────────────────────
def validate_keys(google_key: str) -> tuple[bool, str]:
-<<<<<<< HEAD
-=======
"""Check that a Google API key was provided, returning a success flag and error message."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
if not google_key.strip():
return False, "Google API key is required."
return True, ""
def ingest_document(file, chunk_size, chunk_overlap, google_key):
-<<<<<<< HEAD
-=======
"""Validate inputs and run the uploaded file through the ingest pipeline, updating the status panel."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
if file is None:
return gr.update(value="No file uploaded.", visible=True), gr.update(value=None, visible=False)
@@ -70,10 +57,7 @@ def ingest_document(file, chunk_size, chunk_overlap, google_key):
def run_query(question, n_hypothetical, n_results, google_key):
-<<<<<<< HEAD
-=======
"""Validate inputs, run the HyDE query pipeline, and format the hypothetical docs, chunks, and answer for display."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
if not question.strip():
return "", "", ""
@@ -119,10 +103,7 @@ def run_query(question, n_hypothetical, n_results, google_key):
def clear_all():
-<<<<<<< HEAD
-=======
"""Reset the pipeline and clear all UI fields back to their initial state."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
global pipeline
if pipeline is not None:
pipeline.clear()
diff --git a/rag_apps/hyde_rag/embedder.py b/rag_apps/hyde_rag/embedder.py
index 704dba0..bd6abd5 100644
--- a/rag_apps/hyde_rag/embedder.py
+++ b/rag_apps/hyde_rag/embedder.py
@@ -10,11 +10,7 @@ class GeminiEmbedder:
"""Wraps the google-genai SDK to embed text using Gemini Embedding 2.
Also provides hyde_embed(), which embeds N hypothetical documents and
-<<<<<<< HEAD
- returns their averaged vector — the core of the HyDE retrieval strategy.
-=======
returns their averaged vector, the core of the HyDE retrieval strategy.
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
"""
MODEL = "gemini-embedding-2"
diff --git a/rag_apps/hyde_rag/pyproject.toml b/rag_apps/hyde_rag/pyproject.toml
index 648a474..0daaafc 100644
--- a/rag_apps/hyde_rag/pyproject.toml
+++ b/rag_apps/hyde_rag/pyproject.toml
@@ -1,11 +1,7 @@
[project]
name = "hyde-rag"
version = "0.1.0"
-<<<<<<< HEAD
-description = "HyDE RAG pipeline — Hypothetical Document Embeddings with Gemini 3 Flash and Gemini Embedding 2"
-=======
description = "HyDE RAG pipeline using Hypothetical Document Embeddings with Gemini 3 Flash and Gemini Embedding 2"
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
requires-python = ">=3.11"
dependencies = [
diff --git a/rag_apps/hyde_rag/rag.py b/rag_apps/hyde_rag/rag.py
index 768303a..d68c60e 100644
--- a/rag_apps/hyde_rag/rag.py
+++ b/rag_apps/hyde_rag/rag.py
@@ -18,11 +18,7 @@ from langchain_text_splitters import RecursiveCharacterTextSplitter
from embedder import GeminiEmbedder
-<<<<<<< HEAD
-# ── Prompts ────────────────────────────────────────────────────────────────────
-=======
# Prompts
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
HYPOTHETICAL_PROMPT = """\
You are a knowledgeable assistant. A user has asked the following question:
@@ -30,11 +26,7 @@ You are a knowledgeable assistant. A user has asked the following question:
"{question}"
Write a detailed, factual hypothetical document excerpt that directly answers \
-<<<<<<< HEAD
-this question. Write it as if extracted from a real reference document — \
-=======
this question. Write it as if extracted from a real reference document, \
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
specific, informative, and self-contained. Do not explain that it is hypothetical.
"""
@@ -52,11 +44,7 @@ Answer:
"""
-<<<<<<< HEAD
-# ── Pipeline ───────────────────────────────────────────────────────────────────
-=======
# Pipeline
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
class HyDERAG:
"""End-to-end HyDE retrieval-augmented generation pipeline."""
@@ -71,11 +59,7 @@ class HyDERAG:
self._collection = self._chroma.get_or_create_collection(self.COLLECTION)
self.doc_info: dict | None = None
-<<<<<<< HEAD
- # ── Ingest ──────────────────────────────────────────────────────────────
-=======
# Ingest
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
def ingest(
self,
@@ -137,11 +121,7 @@ class HyDERAG:
}
return self.doc_info
-<<<<<<< HEAD
- # ── Query ───────────────────────────────────────────────────────────────
-=======
# Query
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
def _generate_hypothetical_docs(self, question: str, n: int) -> list[str]:
"""Use Gemini 3 Flash to generate N hypothetical answer documents."""
@@ -174,15 +154,6 @@ class HyDERAG:
n_results = min(n_results, self._collection.count())
-<<<<<<< HEAD
- # Step 1 — generate hypothetical documents
- hypo_docs = self._generate_hypothetical_docs(question, n_hypothetical)
-
- # Step 2 — HyDE embedding (average of hypothetical doc embeddings)
- hyde_vector = self.embedder.hyde_embed(hypo_docs)
-
- # Step 3 — retrieve from ChromaDB using the HyDE vector
-=======
# Step 1: generate hypothetical documents
hypo_docs = self._generate_hypothetical_docs(question, n_hypothetical)
@@ -190,7 +161,6 @@ class HyDERAG:
hyde_vector = self.embedder.hyde_embed(hypo_docs)
# Step 3: retrieve from ChromaDB using the HyDE vector
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
results = self._collection.query(
query_embeddings=[hyde_vector],
n_results=n_results,
@@ -198,11 +168,7 @@ class HyDERAG:
retrieved_texts = results["documents"][0]
retrieved_meta = results["metadatas"][0]
-<<<<<<< HEAD
- # Step 4 — generate final answer
-=======
# Step 4: generate final answer
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
context = "\n\n---\n\n".join(retrieved_texts)
response = self.client.models.generate_content(
model=self.MODEL_ID,