Skip to content

bug(llm): parse_host_port ignores URL path — Ollama base_url with /v1 suffix produces 404 on embed #1832

@bug-ops

Description

@bug-ops

Summary

parse_host_port() in crates/zeph-llm/src/ollama.rs uses rfind(':') to split host and port. When base_url contains a path component (e.g. http://localhost:11434/v1), the function incorrectly returns the full URL-with-path as the host, causing all Ollama API calls to use a double-path URL.

Root cause

fn parse_host_port(url: &str) -> (String, u16) {
    let url = url.trim_end_matches('/');
    if let Some(colon_pos) = url.rfind(':') {
        let port_str = &url[colon_pos + 1..]; // "11434/v1" — not a valid u16
        if let Ok(port) = port_str.parse::<u16>() { ... }
    }
    (url.to_string(), 11434) // fallback: returns "http://localhost:11434/v1" as host
}

Then url_str() appends / and the caller appends api/embed:

"http://localhost:11434/v1/" + "api/embed" = "http://localhost:11434/v1/api/embed"  → 404

Reproduction

[llm.ollama]
base_url = "http://localhost:11434/v1"  # <-- path suffix

With memory.graph.note_linking.enabled = true (or any path that calls provider.embed() on the Ollama provider):

DEBUG note_linking: embed failed for entity "alice": HTTP 404 Not Found

Workaround: use base_url = "http://localhost:11434" (without /v1).

Expected behavior

parse_host_port should strip any path component before splitting host:port. E.g. use url::Url::parse() which is already a workspace dependency, or strip path with split_once('/').0 after the port.

Impact

Silent 404 for all users who configure Ollama base_url with a /v1 suffix (common pattern for OpenAI-compatible setups). Affects embeddings, note linking, entity resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingllmzeph-llm crate (Ollama, Claude)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions