Skip to content

fix: align Gemini viewer embedding test#2050

Open
RerankerGuo wants to merge 15 commits into
MemTensor:dev-v2.0.23from
RerankerGuo:fix/gemini-viewer-embedding-test
Open

fix: align Gemini viewer embedding test#2050
RerankerGuo wants to merge 15 commits into
MemTensor:dev-v2.0.23from
RerankerGuo:fix/gemini-viewer-embedding-test

Conversation

@RerankerGuo

Copy link
Copy Markdown

Description

Related Issue (Required): Fixes #1241

Aligns the Viewer Gemini embedding test with the runtime Gemini embedding provider.

The Viewer test path was still using the old v1 ... :embedContent request shape and parsed embedding.values. The runtime provider uses the Gemini batch embedding API instead. This change makes the Viewer test use v1beta ... :batchEmbedContents, sends a requests array, parses embeddings[0].values, honors a user-provided endpoint, and updates the default embedding model to gemini-embedding-001 in both the provider and Viewer defaults.

A regression test checks the Viewer path, provider default, and UI default stay aligned.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Commands run:

node - <<'NODE'
const fs = require('fs');
const server = fs.readFileSync('apps/memos-local-openclaw/src/viewer/server.ts', 'utf8');
const provider = fs.readFileSync('apps/memos-local-openclaw/src/embedding/providers/gemini.ts', 'utf8');
const html = fs.readFileSync('apps/memos-local-openclaw/src/viewer/html.ts', 'utf8');
const test = fs.readFileSync('apps/memos-local-openclaw/tests/gemini-viewer-test.test.ts', 'utf8');
if (!server.includes('v1beta/models/${geminiModel}:batchEmbedContents')) throw new Error('viewer Gemini batch endpoint missing');
if (!server.includes('requests: [{')) throw new Error('viewer Gemini batch request missing');
if (!server.includes('json?.embeddings?.[0]?.values')) throw new Error('viewer Gemini batch response parse missing');
if (server.includes(':embedContent?key=${apiKey}')) throw new Error('old embedContent viewer path remains');
if (!provider.includes('cfg.model ?? "gemini-embedding-001"')) throw new Error('provider Gemini default not updated');
if (!html.includes("embModel:'gemini-embedding-001'")) throw new Error('viewer Gemini default not updated');
if (!test.includes('Gemini viewer embedding test')) throw new Error('regression test missing');
console.log('Gemini viewer embedding static checks passed');
NODE

Result: Gemini viewer embedding static checks passed.

Also attempted:

cd apps/memos-local-openclaw
npm test -- --run tests/gemini-viewer-test.test.ts
npm run build
make format

npm test is blocked because vitest is not installed. npm run build is blocked because tsc is not installed. make format is blocked because poetry is not installed.

Checklist

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

harvey_xiang and others added 14 commits April 23, 2026 19:38
## Description

Please include a summary of the change, the problem it solves, the
implementation approach, and relevant context. List any dependencies
required for this change.

Related Issue (Required):  Fixes #issue_number

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (does not change functionality, e.g. code style
improvements, linting)
- [ ] Documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration

- [ ] Unit Test
- [ ] Test Script Or Test Steps (please provide)
- [ ] Pipeline Automated API Test (please provide)

## Checklist

- [ ] I have performed a self-review of my own code | 我已自行检查了自己的代码
- [ ] I have commented my code in hard-to-understand areas |
我已在难以理解的地方对代码进行了注释
- [ ] I have added tests that prove my fix is effective or that my
feature works | 我已添加测试以证明我的修复有效或功能正常
- [ ] I have created related documentation issue/PR in
[MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) (if applicable) |
我已在 [MemOS-Docs](https://github.com/MemTensor/MemOS-Docs) 中创建了相关的文档
issue/PR(如果适用)
- [ ] I have linked the issue to this PR (if applicable) | 我已将 issue
链接到此 PR(如果适用)
- [ ] I have mentioned the person who will review this PR | 我已提及将审查此 PR
的人

## Reviewer Checklist
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] Made sure Checks passed
- [ ] Tests have been provided
Translated an untranslated JSON `description` field in
`docs/cn/open_source/modules/dream.md` from English to Chinese.
@RerankerGuo RerankerGuo marked this pull request as ready for review July 8, 2026 05:42
@RerankerGuo

Copy link
Copy Markdown
Author

This draft is now Ready for review. Cloud test-engine rerun on dev-v2.0.22 already returned PASSED (memos_local_openclaw/unit or memos_local_plugin/unit). Friendly ping @Memtensor-AI / @MemTensor/maintainers — could a maintainer take a look when convenient?

@RerankerGuo

Copy link
Copy Markdown
Author

Hi @Memtensor-AI / @CarltonXiang — friendly ping on this draft.

Quick observation: this PR still has base branch main, but MemTensor/MemOS's current merge flow is into dev-v2.0.22 (every recent PR #2065 / #2058 / #2047 / #2046 / #2042 / #2034 / #2033 / #2026 lands on dev-v2.0.22). The bot already retargeted the base SHA for testing and cloud test-engine returned PASSED against dev-v2.0.22 on every rerun.

Could a maintainer please change the base branch from maindev-v2.0.22 (Edit → base branch dropdown) so this can enter the normal merge queue? The head commit is a single focused change and does not depend on any main-only commits.

Thanks!

@RerankerGuo

Copy link
Copy Markdown
Author

Hi @syzsunshine219 — looks like you've merged 35 of the last 50 PRs on this repo. Friendly ping on this one.

This draft (and the other 21 OPEN PRs I have here) is small, single-commit, has cloud test-engine PASSED, and is fully mergeable. The only thing blocking it is that the base branch dropdown still says main — every recent merge (e.g. #2038, #2037, #2034, #2032) landed on dev-v2.0.22.

When you have a moment, would you mind one of:

  1. Flipping the base branch on this PR from maindev-v2.0.22 (Edit → base branch dropdown), or
  2. Telling me which base branch you'd prefer and I'll re-push accordingly.

Both fix and feature PRs in this batch are independent — each can be reviewed/merged on its own. Happy to rebase / split / drop any that don't fit the direction.

Thanks!

@RerankerGuo RerankerGuo force-pushed the fix/gemini-viewer-embedding-test branch from 6afb2ab to 98e5fb7 Compare July 8, 2026 07:45
@Memtensor-AI Memtensor-AI added the needs-audit Requires manual audit before merge label Jul 8, 2026
@Memtensor-AI Memtensor-AI changed the base branch from main to dev-v2.0.23 July 8, 2026 11:25
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2050
Task: manual-ocr:MemTensor/MemOS#2050
Base: main
Head: fix/gemini-viewer-embedding-test

🔍 OpenCodeReview found 2 issue(s) in this PR.

⚠️ 1 warning(s) occurred during review.


1. apps/memos-local-openclaw/src/viewer/server.ts (L3882-L3883)

Security: The API key is always appended as a query parameter to the URL. When a user supplies a custom endpoint, the key=<apiKey> is appended and sent to that user-controlled endpoint. This could expose the Gemini API key to an unintended third-party server.

Additionally, if the user-provided endpoint already contains key=... in its query string, the key will be duplicated (once in the existing URL, once appended), which can cause authentication issues or unexpected behavior.

Suggestion: If a custom endpoint is provided, avoid appending the API key as a query parameter. Instead, pass it via the Authorization header or simply don't append it when the endpoint is user-supplied. At minimum, check whether key= is already present before appending.

💡 Suggested Change

Before:

      const separator = geminiEndpoint.includes("?") ? "&" : "?";
      const url = `${geminiEndpoint}${separator}key=${apiKey}`;

After:

      // Only append the API key for the default Gemini endpoint; for custom
      // endpoints the caller is responsible for authentication.
      const url = endpoint
        ? geminiEndpoint
        : `${geminiEndpoint}?key=${apiKey}`;

2. apps/memos-local-openclaw/src/viewer/server.ts (L3888-L3891)

When the user provides a custom endpoint, the model field in the batch request body is still hardcoded to models/${geminiModel} (defaulting to models/gemini-embedding-001). If the custom endpoint targets a different model or a proxy that routes based on the model field, this mismatch could silently produce incorrect dimension counts or outright request failures.

Suggestion: When a custom endpoint is provided, consider omitting the model field or deriving it from the provided model parameter directly.


🧹 Filtered 2 low-confidence OCR finding(s) before posting/fix-loop (duplicate: 2).

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI Memtensor-AI added the area:plugin Plugin, adapter, bridge, or apps layer | 插件、适配器、桥接层或 apps 目录 label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:plugin Plugin, adapter, bridge, or apps layer | 插件、适配器、桥接层或 apps 目录 needs-audit Requires manual audit before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Published memos-local package appears to have a Viewer Gemini test bug not traceable in current repo source

4 participants