Skip to content

Module: Gerd/rag_frontend.py#57

Open
mouayadkarimeh wants to merge 10 commits into
caretech-owl:mainfrom
mouayadkarimeh:gerd/rag_frontend.py
Open

Module: Gerd/rag_frontend.py#57
mouayadkarimeh wants to merge 10 commits into
caretech-owl:mainfrom
mouayadkarimeh:gerd/rag_frontend.py

Conversation

@mouayadkarimeh

@mouayadkarimeh mouayadkarimeh commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR introduces a new module rag_frontend.py, which provides a frontend interface for interacting with LLMs using a Retrieval-Augmented Generation (RAG) pipeline.

Features

  • LLM Interaction Interface – Enables users to submit queries and receive answers with relevant sources
  • RAG Integration – support RAG Concept, enhances response quality using external knowledge
  • difault-think-No-Think Mode Support – Adds /no_think parameter
  • **Model Switching:
    • qwen2.5-0.5B-instruct
    • qwen3-0.6B
    • qwen3.5-0.8b
    • qwen3.5-9b

Work in Progress

  • **reasining in qwen3.5 dosent work always proberly.

@mouayadkarimeh mouayadkarimeh left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so much files mistakly lands on the same PR. trying to remove alle this but too much komplex . the main commit it the last one
create new module rag_frontend.py: b700c29 -2 hours ago

@mouayadkarimeh mouayadkarimeh left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

committed eliminated successfully. ready to review

Comment thread gerd/frontends/rag_frontend.py Outdated
Comment thread gerd/frontends/rag_frontend.py Outdated
minimum=1, maximum=10, step=1, value=3, label="Number of Sources"
)
strategy_dropdown = gr.Dropdown(
choices=["similarity", "mmr"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is another strategy in Faiss

Comment thread gerd/frontends/rag_frontend.py
@mouayadkarimeh

mouayadkarimeh commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Aktueller Stand der Entwicklung

1. Lösung des LLM-Wechsel-Problems (qa_service.py): Das Problem beim Modellwechsel wurde durch die Funktion reinit_qa_service() in der qa_service.py gelöst. Sobald ein Modell gewechselt wird, wird der Dienst mit dem aktuellen qa_config-Objekt (welches die Konfigurationen für Modell, Prompts etc. enthält) neu initialisiert. In der rag_frontend.py (Ergebnis-Demonstrator) wird zudem der Thread-Zugriff überwacht und über einen MODEL_SWITCH_LOCK abgesichert.

2. Parameter-Steuerung in rag_frontend.pyI Steuerungselemente zur Manipulation zusätzlicher Parameter implementiert, insbesondere für die chunk_size (Segmentgröße) und den chunk_overlap (Überlappung der Segmente).

3. Visualisierung der Denkprozesse (Thoughts) In der rag_frontend.py wurde ein dediziertes Feld für „Thoughts“ hinzugefügt. Um eine bessere Übersicht zu gewährleisten. Die relevanten Quellen (Sources), der Denkprozess (Thoughts) und die finale Antwort (Final Answer)werden nun nebeneinander dargestellt.

4.. Integration von Qwen 3.5 und Reasoning-Problematik Aktuell wird untersucht, warum die Reasoning-Fähigkeiten (Denkprozesse) bei der Qwen3.5 -Serie unterschiedlich unterstützt werden:

-Hugging Face Dokumentation von qwen3.5: Laut Dokumentation arbeitet Qwen standardmäßig im „Non-Think“-Modus. Zudem Laut Huggingface Dokumentation wird kein Reasoning über Prompt-Präfixe unterstützt, sondern parameter_präfixe über ein spezifisches Parameter-Flag (enable_thinking).

-Architekturentscheidung: Für Qwen-Modelle kommt daher die Klasse remoteLLM aus der loader.py zum Einsatz, während Qwen3 weiterhin lokal über TransformerLLM laufen.

-Testumgebung (LM Studio): Obwohl das enable_thinking-Flag korrekt als API-Parameter übergeben wird und das „Think“-Flag in der Anfrage erscheint, bleibt das Problem bei der Version Qwen-0.8b bestehen. Bei der größeren Version Qwen-9b funktioniert das Reasoning hingegen einwandfrei.Erkenntnis: Das enable_thinking-Flag ist ein reiner API-/Server-Flag (für LM Studio, vLLM oder Ollama) und wird von der nativen Hugging Face transformers-Bibliothek nicht direkt als Modell-Parameter unterstützt.

-Prerequistes für den Entwicklungsmodus:Für den Remote-Modus (remoteLLM in loader.py) LM Studio soll installiert und das entsprechende Qwen-Modell (0.8b oder 9b) geladen sein. Hilfsfunktionen in der loader.py sorgen dafür, dass die Server-Antworten in der Python-Ausführung korrekt verarbeitet und visualisiert werden.

Beispiel:

Screenshot 2026-05-07 130440 Screenshot 2026-05-07 130422

Comment thread llama-cpp-python
Comment thread gerd/frontends/qa_frontend.py
Comment thread gerd/qa/qa_service.py Outdated
Comment thread gerd/loader.py

model_kwargs = config.extra_kwargs or {}
model_kwargs = dict(config.extra_kwargs or {})
model_kwargs.pop("enable_thinking", None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you delete those entries? If you would left them here, these would trigger the Not Implemented error below instead of quietly being ignored...

Comment thread gerd/loader.py

import requests
For OpenAI-compatible endpoints, the request follows the OpenAI API format.
For llama.cpp endpoints, the request follows the llama.cpp server API format.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested both llama.cpp and other endpoints?

Comment thread gerd/rag.py

@mouayadkarimeh mouayadkarimeh left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv run ruff check gerd -> all passed


uv run mypy gerd -> Success: no issues found in 37 files


uv run poe test -> 1 Error: llama.cpp


uv run poe test_manuel -> 1 passed, 5 deselected, 1 warning


Screenshot 2026-05-22 122552.png
Screenshot 2026-05-22 121052.png
Screenshot 2026-05-22 122517.png
Screenshot 2026-05-22 122533.png

@mouayadkarimeh mouayadkarimeh left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2026-05-22 125755.png

Comment thread gerd/qa/qa_service.py
from langchain_community.document_loaders import PyPDFLoader, TextLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter

# from gerd.benchmark import make_prompt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comments like this

Comment on lines +93 to +98
if "qwen3.5" in _CURRENT_MODEL.lower():
qa_config.model.endpoint = ModelEndpoint(
url="http://localhost:8000",
type="openai",
key=None,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you manually override the config here?

qa_config.model.endpoint = None
qa_config.embedding.chunk_size = chunk_size
qa_config.embedding.chunk_overlap = chunk_overlap
TRANSPORTER.reinit_qa_service(qa_config)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although you use the reinit_qa_service here, the parameters for the chunk_size and overlap are not set in the base class (just tested it). So recheck the implementation in QA_Service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants