Skip to content

RAG source citation URLs are mangled when metadata contains absolute URLs #420

Description

@juananpe

When a LAMB assistant using a RAG processor (Simple RAG, Context-Aware RAG, or Hierarchical RAG) answers a query and cites its sources, the reference URLs in the response are broken. The base URL of the KB server is incorrectly prepended to metadata URLs that are already absolute, producing mangled URLs like:

http://kb:9090http://localhost:9090/static/1/testbge/cf047e7fa1f646dfa025b1ed56b48528.html

Steps to Reproduce

  1. Create a Knowledge Base and ingest a document (e.g. via the markitdown plugin).
  2. Create an assistant with Simple RAG (or Context-Aware / Hierarchical RAG) using that KB.
  3. Ask the assistant a question that triggers a source citation.
  4. Observe the "Referencia" / source link in the assistant's response.

Expected Behavior

The source link should be a valid, clickable URL pointing to the document, e.g.:

http://<public-host>:9090/static/1/testbge/cf047e7fa1f646dfa025b1ed56b48528.html

Actual Behavior

The URL is a concatenation of the internal KB server URL (http://kb:9090) and the metadata URL (which is already an absolute URL), resulting in an invalid URL that cannot be opened.

Root Cause

In backend/lamb/completions/rag/ (affected files: simple_rag.py, hierarchical_rag.py, context_aware_rag.py), the code that builds source citation URLs unconditionally prepends KB_SERVER_URL to the URL fields stored in document metadata:

original_url = f"{KB_SERVER_URL}{metadata['original_file_url']}"
markdown_url = f"{KB_SERVER_URL}{metadata['markdown_file_url']}"
source_url   = f"{KB_SERVER_URL}{metadata['file_url']}"

The markitdown ingestion plugins store absolute URLs in these metadata fields (e.g. http://localhost:9090/static/...), so prepending the KB server base URL produces a doubled, invalid URL.

The code should check whether the metadata value is already an absolute URL before prepending the base URL.

Affected Files

  • backend/lamb/completions/rag/simple_rag.py
  • backend/lamb/completions/rag/hierarchical_rag.py
  • backend/lamb/completions/rag/context_aware_rag.py

Screenshot showing the problem:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    CriticalbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions