Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to CodeGraph are documented here. Versions follow
[Semantic Versioning](https://semver.org/). Releases from 0.18.1 on are tagged
`vX.Y.Z`; earlier ones `vscode/vX.Y.Z`.

## [Unreleased]

### Fixed

- **Windows: ONNX Runtime download falls back to NuGet.** `microsoft/onnxruntime`
was removed from GitHub in November 2026, so the release URL baked into the
binary returns 404 and the ONNX embedding models (`bge-small`, `jina-code-v2`,
`granite-97m`) could not start — semantic search was silently unavailable while
the structural tools kept working. `ensure_ort_dll()` now retries the same
version from the `Microsoft.ML.OnnxRuntime` nupkg (`runtimes/win-x64/native/onnxruntime.dll`)
before giving up. A DLL already present next to the executable or in
`~/.codegraph/fastembed_cache/ort/` is still used as-is, so nothing changes for
working installs.

## [0.21.1] - 2026-10-10

VS Code extension only; the engine stays 0.21.0.
Expand Down
143 changes: 119 additions & 24 deletions crates/codegraph-memory/src/embedding/fastembed_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,53 +582,148 @@ fn ensure_ort_dll(cache_dir: &std::path::Path) -> Result<()> {
std::fs::create_dir_all(&dll_dir)
.map_err(|e| MemoryError::model(format!("Failed to create ORT cache dir: {e}")))?;

// Download the official release zip
let url = format!(
// Primary source: the official GitHub release zip. GitHub removed
// microsoft/onnxruntime on ~2026-11-17 (assets and repo return 404), so
// fall back to the NuGet package, which ships the same DLL layout as
// runtimes/win-x64/native/onnxruntime.dll.
let gh_url = format!(
"https://github.com/microsoft/onnxruntime/releases/download/v{ORT_VERSION}/onnxruntime-win-x64-{ORT_VERSION}.zip"
);
let dll_name_in_zip = format!("onnxruntime-win-x64-{ORT_VERSION}/lib/onnxruntime.dll");

if let Err(gh_err) = extract_zip_member(&gh_url, &dll_name_in_zip, &dll_dir, &dll_path) {
log::warn!("ONNX Runtime GitHub download failed ({gh_err}); trying NuGet...");
let nuget_url = format!(
"https://api.nuget.org/v3-flatcontainer/microsoft.ml.onnxruntime/{ORT_VERSION}/microsoft.ml.onnxruntime.{ORT_VERSION}.nupkg"
);
extract_zip_member(
&nuget_url,
"runtimes/win-x64/native/onnxruntime.dll",
&dll_dir,
&dll_path,
)?;
}

// Clean up zip
let _ = std::fs::remove_file(dll_dir.join("onnxruntime.zip"));

log::info!(
"ONNX Runtime v{} DLL installed at {}",
ORT_VERSION,
dll_path.display()
);
std::env::set_var("ORT_DYLIB_PATH", &dll_path);

let response = ureq::get(&url)
Ok(())
}

/// Download `url` (a .zip or .nupkg) and extract `member` to `out`.
/// The archive is streamed to a temp file next to `out` and removed afterwards.
#[cfg(target_os = "windows")]
fn extract_zip_member(
url: &str,
member: &str,
tmp_dir: &std::path::Path,
out: &std::path::Path,
) -> Result<()> {
let response = ureq::get(url)
.call()
.map_err(|e| MemoryError::model(format!("Failed to download ONNX Runtime: {e}")))?;

// Stream to a temp file
let zip_path = dll_dir.join("onnxruntime.zip");
let zip_path = tmp_dir.join("onnxruntime.zip");
let mut zip_file = std::fs::File::create(&zip_path)
.map_err(|e| MemoryError::model(format!("Failed to create temp zip: {e}")))?;
std::io::copy(&mut response.into_reader(), &mut zip_file)
.map_err(|e| MemoryError::model(format!("Failed to write zip: {e}")))?;
drop(zip_file);

// Extract onnxruntime.dll from the zip
let zip_file = std::fs::File::open(&zip_path)
let result = extract_member_from_zip(&zip_path, member, out);

let _ = std::fs::remove_file(&zip_path);
result
}

/// Copy a single entry out of an archive that is already on disk.
/// Split from the download so the extraction can be tested without a network.
#[cfg(target_os = "windows")]
fn extract_member_from_zip(
zip_path: &std::path::Path,
member: &str,
out: &std::path::Path,
) -> Result<()> {
let zip_file = std::fs::File::open(zip_path)
.map_err(|e| MemoryError::model(format!("Failed to open zip: {e}")))?;
let mut archive = zip::ZipArchive::new(zip_file)
.map_err(|e| MemoryError::model(format!("Failed to read zip: {e}")))?;

let dll_name_in_zip = format!("onnxruntime-win-x64-{ORT_VERSION}/lib/onnxruntime.dll");

let mut dll_entry = archive.by_name(&dll_name_in_zip).map_err(|e| {
let mut entry = archive.by_name(member).map_err(|e| {
MemoryError::model(format!(
"onnxruntime.dll not found in zip at '{dll_name_in_zip}': {e}"
"onnxruntime.dll not found in zip at '{member}': {e}"
))
})?;

let mut out_file = std::fs::File::create(&dll_path)
let mut out_file = std::fs::File::create(out)
.map_err(|e| MemoryError::model(format!("Failed to create DLL file: {e}")))?;
std::io::copy(&mut dll_entry, &mut out_file)
std::io::copy(&mut entry, &mut out_file)
.map_err(|e| MemoryError::model(format!("Failed to extract DLL: {e}")))?;
Ok(())
}

// Clean up zip
let _ = std::fs::remove_file(&zip_path);
#[cfg(all(test, target_os = "windows"))]
mod ort_extract_tests {
use super::extract_member_from_zip;
use std::io::Write;

fn write_archive(path: &std::path::Path, members: &[(&str, &[u8])]) {
let file = std::fs::File::create(path).expect("create archive");
let mut writer = zip::ZipWriter::new(file);
for (name, bytes) in members {
writer
.start_file(*name, zip::write::SimpleFileOptions::default())
.expect("start entry");
writer.write_all(bytes).expect("write entry");
}
writer.finish().expect("finish archive");
}

log::info!(
"ONNX Runtime v{} DLL installed at {}",
ORT_VERSION,
dll_path.display()
);
std::env::set_var("ORT_DYLIB_PATH", &dll_path);
#[test]
fn extracts_the_requested_member_only() {
let dir = tempfile::tempdir().expect("tempdir");
let zip_path = dir.path().join("pkg.nupkg");
write_archive(
&zip_path,
&[
("runtimes/win-x64/native/onnxruntime.dll", b"ORT-DLL-BYTES"),
("other.txt", b"ignore"),
],
);

Ok(())
let out = dir.path().join("onnxruntime.dll");
extract_member_from_zip(&zip_path, "runtimes/win-x64/native/onnxruntime.dll", &out)
.expect("extract member");

assert_eq!(
std::fs::read(&out).expect("read extracted file"),
b"ORT-DLL-BYTES"
);
}

#[test]
fn missing_member_is_an_error() {
let dir = tempfile::tempdir().expect("tempdir");
let zip_path = dir.path().join("pkg.nupkg");
write_archive(&zip_path, &[("other.txt", b"x")]);

let err = extract_member_from_zip(
&zip_path,
"runtimes/win-x64/native/onnxruntime.dll",
&dir.path().join("out.dll"),
)
.expect_err("missing member must fail");

assert!(
format!("{err}").contains("not found in zip"),
"unexpected error: {err}"
);
}
}

#[cfg(test)]
Expand Down