issue: Citation Events not linked correctly #5929

Closed
opened 2025-11-11 16:39:07 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @Patsch36 on GitHub (Jul 31, 2025).

Check Existing Issues

  • I have searched the existing issues and discussions.
  • I am using the latest version of Open WebUI.

Installation Method

Git Clone

Open WebUI Version

latest

Ollama Version (if applicable)

No response

Operating System

Windows 11

Browser (if applicable)

Firefox

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

OpenWebui emits the citation events correctly and when clicking on the event badge, the right source is shown

Actual Behavior

Badges were emitted right, but only when clicking on the first badge the popup opens, on the other not.
When clicking on the first badge, all sources are listed

https://github.com/user-attachments/assets/4bebc8f6-70d4-47a0-bb26-c528f3f4584a

Steps to Reproduce

  1. New Tool at Worspace/Tools

  2. create the following Code:
    `async def get_patent_by_context(
    self, context: str, event_emitter: Callable[[dict], Any]
    ) -> List[dict]:
    """
    Retrieve patent information based on context/user questions. The method returns the 4 most likely patents ordered from most likely to least likely.
    :param context: The context to search for in the patent database.
    :param event_emitter: Open WebUI event emitter for status updates.
    """
    db_cfg = DBConfig(
    host="localhost",
    port=5432,
    user="postgres",
    password="postgres",
    dbname="postgres",
    vector_dim=1024,
    embedding_model=AzureOpenAIEmbeddingModel(
    "text-embedding-3-large", dimensions=1024
    ),
    )
    db = VectorDB(db_cfg)

     embedding = db.create_embedding_vector(context)
    
     statement = f"""
         SELECT pat.country, pat.doc_number, pat.kind, pat.system, pat.family_id, 1 - (p.content_embedding <=> '{embedding}') AS similarity, p.content
             FROM patents pat
             JOIN fulltext_documents ftd ON pat.id = ftd.patent_id
             JOIN paragraphs p ON ftd.id = p.fulltext_document_id
             ORDER BY similarity DESC
             LIMIT 5;
         """
     try:
         result = db.execute_sql(statement)
    
         # String vorbereiten, der am Ende an das LLM geht
         info_list_for_llm = []
    
         # Korrekte Verwendung von enumerate: (index, value)
         for index, res in enumerate(result):
             # 1. Daten aus der DB-Zeile extrahieren (Beispiel!)
             patent_family = res[0]
             patent_id = res[1]
             patent_kind = res[2]
             patent_summary = res[-1]
             patent_confidence = res[-2]
    
             patent_title = patent_family + patent_id + patent_kind
    
             # Eine lesbare Info für die Zitation und den LLM-Input
             info_snippet = (
                 f"Das Patent '{patent_title}' beschreibt: {patent_summary}"
             )
    
             # 2. Die Quelle für das citation-Event erstellen (Syntax korrigiert!)
             source = {
                 "name": f"Patent: {patent_title}",
                 "url": patent_summary
                 + f"with {patent_confidence}% condifentially.",
             }
    
             # 3. Citation-Event an die UI senden.
             await __event_emitter__(
                 {
                     "type": "citation",
                     "data": {"source": source, "document": [patent_title]},
                 }
             )
    
             # 4. Den Info-String FÜR DAS LLM mit dem Marker versehen!
             #    Die Nummerierung [index + 1] muss hier rein.
             info_list_for_llm.append(f"- {patent_title} [{index + 1}]")
    
         if not info_list_for_llm:
             return "Ich konnte keine passenden Patente zu dieser Anfrage finden."
    
         # 5. Die finale Anweisung für das LLM zusammenbauen
         final_prompt_for_llm = f"""
         Fasse die folgenden Informationen aus den Patentrecherchen in einem flüssigen und gut lesbaren Text zusammen.
         Behalte dabei die Quellenverweise wie [1], [2] usw. an den exakten Stellen im Text bei, damit die Aussagen nachvollziehbar bleiben.
    
         Gefundene Informationen:
         {''.join(info_list_for_llm)}
         """
    
         return final_prompt_for_llm
     except Exception as e:
         return [f"Error retrieving patent by context: {e}"]`
    

(result from database is e.g. [ [ "EP", "1114752", "B1", "ops.epo.org", "7627007", 0.7068290921100706, "[0002] Zumeist werden Batterieleitungen in Fahrzeugen zumindest zum Teil im\n Innenraum verlegt. Dies trifft vor allem dann zu, wenn sich die Batterie im Heck\n des Fahrzeugs befindet und der Anlasser bzw. Generator im vorderen Bereich\n angeordnet ist." ], [ "WO", "2019166148", "A1", "ops.epo.org", "65243512", 0.6923666963140184, "BATTERIEANSCHLUSS F\u00dcR FAHRZEUGBORDNETZ" ], [ "WO", "2021073977", "A1", "ops.epo.org", "72801491", 0.6666671435037728, "Fahrzeugbordnetz" ], [ "WO", "2005078891", "A1", "ops.epo.org", "34684701", 0.6621443427887179, "Vorzugsweise weist die Verbindungsleitung zwischen Batterie und dem Stromver- teiler einen Querschnitt von maximal etwa 5 mm2 bei einer Leitungsl\u00e4nge von ma- ximal 2 m, vorzugsweise 1 m auf. Bei diesen Leitungsl\u00e4ngen l\u00e4sst sich die Batterie im Motorraum des Kraftfahrzeugs anordnen, wobei ein besonders niedriger Lei- tungsquerschnitt verwendet werden kann." ], [ "WO", "2024184429", "A1", "ops.epo.org", "90364137", 0.6473367407124266, "Bordnetz f\u00fcr ein Kraftfahrzeug" ] ]

Logs & Screenshots

[tiptap warn]: Duplicate extension names found: ['codeBlock', 'bulletList', 'listItem', 'listKeymap', 'orderedList']. This can lead to issues. 11 index.js:791:13
Uncaught (in promise) TypeError: can't access property "content", oe.messages[Le.id] is undefined
Vt Chat.svelte:1009
Chat.svelte:1009:11
[tiptap warn]: Duplicate extension names found: ['codeBlock', 'bulletList', 'listItem', 'listKeymap', 'orderedList']. This can lead to issues. 2 index.js:791:13
[tiptap warn]: Duplicate extension names found: ['codeBlock', 'bulletList', 'listItem', 'listKeymap', 'orderedList']. This can lead to issues.

Additional Information

No response

Originally created by @Patsch36 on GitHub (Jul 31, 2025). ### Check Existing Issues - [x] I have searched the existing issues and discussions. - [x] I am using the latest version of Open WebUI. ### Installation Method Git Clone ### Open WebUI Version latest ### Ollama Version (if applicable) _No response_ ### Operating System Windows 11 ### Browser (if applicable) Firefox ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior OpenWebui emits the citation events correctly and when clicking on the event badge, the right source is shown ### Actual Behavior Badges were emitted right, but only when clicking on the first badge the popup opens, on the other not. When clicking on the first badge, all sources are listed https://github.com/user-attachments/assets/4bebc8f6-70d4-47a0-bb26-c528f3f4584a ### Steps to Reproduce 1. New Tool at Worspace/Tools 2. create the following Code: `async def get_patent_by_context( self, context: str, __event_emitter__: Callable[[dict], Any] ) -> List[dict]: """ Retrieve patent information based on context/user questions. The method returns the 4 most likely patents ordered from most likely to least likely. :param context: The context to search for in the patent database. :param __event_emitter__: Open WebUI event emitter for status updates. """ db_cfg = DBConfig( host="localhost", port=5432, user="postgres", password="postgres", dbname="postgres", vector_dim=1024, embedding_model=AzureOpenAIEmbeddingModel( "text-embedding-3-large", dimensions=1024 ), ) db = VectorDB(db_cfg) embedding = db.create_embedding_vector(context) statement = f""" SELECT pat.country, pat.doc_number, pat.kind, pat.system, pat.family_id, 1 - (p.content_embedding <=> '{embedding}') AS similarity, p.content FROM patents pat JOIN fulltext_documents ftd ON pat.id = ftd.patent_id JOIN paragraphs p ON ftd.id = p.fulltext_document_id ORDER BY similarity DESC LIMIT 5; """ try: result = db.execute_sql(statement) # String vorbereiten, der am Ende an das LLM geht info_list_for_llm = [] # Korrekte Verwendung von enumerate: (index, value) for index, res in enumerate(result): # 1. Daten aus der DB-Zeile extrahieren (Beispiel!) patent_family = res[0] patent_id = res[1] patent_kind = res[2] patent_summary = res[-1] patent_confidence = res[-2] patent_title = patent_family + patent_id + patent_kind # Eine lesbare Info für die Zitation und den LLM-Input info_snippet = ( f"Das Patent '{patent_title}' beschreibt: {patent_summary}" ) # 2. Die Quelle für das citation-Event erstellen (Syntax korrigiert!) source = { "name": f"Patent: {patent_title}", "url": patent_summary + f"with {patent_confidence}% condifentially.", } # 3. Citation-Event an die UI senden. await __event_emitter__( { "type": "citation", "data": {"source": source, "document": [patent_title]}, } ) # 4. Den Info-String FÜR DAS LLM mit dem Marker versehen! # Die Nummerierung [index + 1] muss hier rein. info_list_for_llm.append(f"- {patent_title} [{index + 1}]") if not info_list_for_llm: return "Ich konnte keine passenden Patente zu dieser Anfrage finden." # 5. Die finale Anweisung für das LLM zusammenbauen final_prompt_for_llm = f""" Fasse die folgenden Informationen aus den Patentrecherchen in einem flüssigen und gut lesbaren Text zusammen. Behalte dabei die Quellenverweise wie [1], [2] usw. an den exakten Stellen im Text bei, damit die Aussagen nachvollziehbar bleiben. Gefundene Informationen: {''.join(info_list_for_llm)} """ return final_prompt_for_llm except Exception as e: return [f"Error retrieving patent by context: {e}"]` (result from database is e.g. `[ [ "EP", "1114752", "B1", "ops.epo.org", "7627007", 0.7068290921100706, "[0002] Zumeist werden Batterieleitungen in Fahrzeugen zumindest zum Teil im\n Innenraum verlegt. Dies trifft vor allem dann zu, wenn sich die Batterie im Heck\n des Fahrzeugs befindet und der Anlasser bzw. Generator im vorderen Bereich\n angeordnet ist." ], [ "WO", "2019166148", "A1", "ops.epo.org", "65243512", 0.6923666963140184, "BATTERIEANSCHLUSS F\u00dcR FAHRZEUGBORDNETZ" ], [ "WO", "2021073977", "A1", "ops.epo.org", "72801491", 0.6666671435037728, "Fahrzeugbordnetz" ], [ "WO", "2005078891", "A1", "ops.epo.org", "34684701", 0.6621443427887179, "Vorzugsweise weist die Verbindungsleitung zwischen Batterie und dem Stromver- teiler einen Querschnitt von maximal etwa 5 mm2 bei einer Leitungsl\u00e4nge von ma- ximal 2 m, vorzugsweise 1 m auf. Bei diesen Leitungsl\u00e4ngen l\u00e4sst sich die Batterie im Motorraum des Kraftfahrzeugs anordnen, wobei ein besonders niedriger Lei- tungsquerschnitt verwendet werden kann." ], [ "WO", "2024184429", "A1", "ops.epo.org", "90364137", 0.6473367407124266, "Bordnetz f\u00fcr ein Kraftfahrzeug" ] ]` ### Logs & Screenshots [tiptap warn]: Duplicate extension names found: ['codeBlock', 'bulletList', 'listItem', 'listKeymap', 'orderedList']. This can lead to issues. 11 [index.js:791:13](http://localhost:7437/node_modules/@tiptap/core/dist/index.js) Uncaught (in promise) TypeError: can't access property "content", oe.messages[Le.id] is undefined Vt Chat.svelte:1009 [Chat.svelte:1009:11](http://localhost:7437/src/lib/components/chat/Chat.svelte) [tiptap warn]: Duplicate extension names found: ['codeBlock', 'bulletList', 'listItem', 'listKeymap', 'orderedList']. This can lead to issues. 2 [index.js:791:13](http://localhost:7437/node_modules/@tiptap/core/dist/index.js) [tiptap warn]: Duplicate extension names found: ['codeBlock', 'bulletList', 'listItem', 'listKeymap', 'orderedList']. This can lead to issues. ### Additional Information _No response_
GiteaMirror added the bug label 2025-11-11 16:39:07 -06:00
Author
Owner

@tjbck commented on GitHub (Jul 31, 2025):

Without proper metadata, video recording you've included is an intended behaviour.

@tjbck commented on GitHub (Jul 31, 2025): Without proper `metadata`, video recording you've included is an intended behaviour.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#5929