Skip to content

feat(embedding): improve robustness with pre-flight checks and URL nprmalization#103

Open
capyBearista wants to merge 1 commit intotickernelz:mainfrom
capyBearista:feat/embedding-robustness
Open

feat(embedding): improve robustness with pre-flight checks and URL nprmalization#103
capyBearista wants to merge 1 commit intotickernelz:mainfrom
capyBearista:feat/embedding-robustness

Conversation

@capyBearista
Copy link
Copy Markdown

This pull request improves the robustness and user experience of the embedding system by handling cases where the local embedding model is unavailable, providing clearer configuration and error messaging, and normalizing embedding API URLs. The changes ensure that users are properly notified if local embeddings cannot be loaded and are guided to configure API-based embeddings as a fallback.

Embedding system robustness and user feedback:

  • Added checks to detect if the local embedding model fails to load (e.g., due to missing native dependencies), and set a flag to prevent repeated attempts. If local embeddings are unavailable and no API-based embedding is configured, a warning toast is shown to the user, and errors during initialization are reported with a descriptive message. (src/services/embedding.ts, src/index.ts) [1] [2] [3] [4]
  • Implemented a preflight check using a child process to verify that the @huggingface/transformers library can be imported before attempting to use local embeddings, improving reliability in diverse environments. (src/services/embedding.ts)

Configuration improvements:

  • Normalized the embeddingApiUrl by automatically appending /v1 if missing and stripping any trailing /embeddings, ensuring consistent API usage and reducing configuration errors. (src/config.ts) [1] [2] [3]
  • Stripped trailing slashes from memoryApiUrl for consistency. (src/config.ts)

Code organization:

  • Imported the embeddingService in the main plugin entry point to support the new initialization and error handling logic. (src/index.ts)

^ Copilot summary

Copilot AI review requested due to automatic review settings May 3, 2026 19:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens embedding initialization and configuration in the plugin by adding local-model preflight/failure handling, surfacing startup feedback to users, and normalizing configured API base URLs before embedding requests are made.

Changes:

  • Added local embedding preflight/import failure tracking in EmbeddingService, plus clearer fallback errors when no API-based embeddings are configured.
  • Added startup toasts in the plugin entrypoint to warn about unavailable local embeddings and report initialization failures.
  • Normalized embedding API URLs to a consistent base form and stripped trailing slashes from memory API URLs in config parsing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/services/embedding.ts Adds local embedding preflight logic, failure state tracking, and updated warmup/embed fallback behavior.
src/index.ts Adds embedding-service-aware startup notifications for warning and error cases.
src/config.ts Adds embedding URL normalization helpers and strips trailing slashes from memory API URLs during config build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.ts
Comment on lines +38 to +45
if (!embeddingService.localEmbeddingsAvailable && !CONFIG.embeddingApiUrl) {
if (ctx.client?.tui) {
ctx.client.tui
.showToast({
body: {
title: "Memory System",
message:
"Local embedding model unavailable. Configure embeddingApiUrl and embeddingApiKey in opencode-mem.jsonc to use API-based embeddings.",
Comment thread src/config.ts
Comment on lines +510 to +512
embeddingApiUrl: fileConfig.embeddingApiUrl
? normalizeEmbeddingUrl(fileConfig.embeddingApiUrl)
: undefined,
Comment thread src/services/embedding.ts
Comment on lines +112 to +114
log("Local embedding model unavailable (native dependency check failed)", {});
this.isWarmedUp = true;
return;
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