Skip to content
Merged
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
59 changes: 59 additions & 0 deletions .github/workflows/catalog-listing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish Embedding catalog listing

# The catalog listing (catalog/listing.yaml + catalog/screenshots) is
# presentation only: a change never implies a release. On main it replaces the
# listing of the entry the catalog already records and requests a publication.

on:
push:
branches: [main]
paths:
- catalog/listing.yaml
- catalog/screenshots/**
- hack/catalog-listing.ts
- .github/workflows/catalog-listing.yml
workflow_dispatch:

permissions:
contents: read

# Shares the writer with the release publisher: one read/merge/PUT at a time.
concurrency:
group: embedding-catalog-publish
cancel-in-progress: false

jobs:
listing:
if: github.repository == 'appthrust/embedding'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
with:
bun-version: 1.4.1
- name: Validate the listing
run: bun hack/publish-entry.ts validate-listing
- name: Submit the listing
id: catalog
env:
CLOUD_API_URL: ${{ vars.CLOUD_API_URL || 'https://api.appthrust.com' }}
CLOUD_CATALOG_ADMIN_TOKEN: ${{ secrets.CLOUD_CATALOG_ADMIN_TOKEN }}
run: bun hack/publish-entry.ts listing
- name: Mint the Cloud workflow dispatch token
if: steps.catalog.outputs.state == 'snapshot'
id: cloud-token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
with:
app-id: ${{ secrets.APPTHRUST_GITHUB_ACTIONS_APP_ID }}
private-key: ${{ secrets.APPTHRUST_GITHUB_ACTIONS_APP_PRIVATE_KEY }}
owner: appthrust
repositories: cloud
- name: Dispatch Cloud catalog publication
if: steps.catalog.outputs.state == 'snapshot'
env:
GH_TOKEN: ${{ steps.cloud-token.outputs.token }}
SNAPSHOT_ID: ${{ steps.catalog.outputs.snapshot_id }}
run: gh api -X POST repos/appthrust/cloud/dispatches -f event_type=catalog-publish -f "client_payload[snapshot_id]=$SNAPSHOT_ID"
64 changes: 64 additions & 0 deletions catalog/listing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
locales:
en:
title: Embedding
tagline: Turns documents into search vectors inside your Project, so Knowledge can find passages by meaning, not only by matching words.
overview: |
Embedding converts text into vectors that capture its meaning, using the EmbeddingGemma model. Knowledge uses these vectors for vector search and hybrid search, so people in the Project can find the right passage even when their question is worded differently from the document.

Nobody needs to open Embedding day to day. When someone adds a document to Knowledge, Knowledge splits it into chunks and saves it once every chunk has been embedded. A search query is embedded the same way and compared with the stored chunks. In Knowledge's search playground you can switch between full-text, vector and hybrid modes and compare the results.

The Dashboard shows Embedding as Ready only after the model has returned a vector at start-up, and lists Knowledge as the app that uses it. You choose whether new versions install automatically or stay pinned until you update. For developers, Embedding also exposes an embeddings API that returns 768-dimensional vectors.

Embedding runs inside the Project, and the model is included in the app. It needs no API key and calls no outside service, so document text does not leave the Project. It runs on CPU; no GPU node is required. Access goes through the Project's sign-in with your organisation account. Installing Knowledge installs Embedding automatically.
ja:
title: Embedding
tagline: プロジェクトの中で文書を検索用のベクトルに変換し、言葉が一致しなくても意味の近い箇所を Knowledge で探せるようにします。
overview: |
Embedding は、EmbeddingGemma モデルで文章を意味のベクトルに変換するアプリです。Knowledge はこのベクトルを使ってベクトル検索とハイブリッド検索を行います。質問と文書で言い回しが違っていても、プロジェクトのメンバーは目的の箇所を見つけられます。

普段の利用で Embedding を直接開く必要はありません。Knowledge に文書を追加すると、Knowledge が文書をチャンクに分け、すべてのチャンクの埋め込みが終わってから保存します。検索するときはクエリも同じように埋め込まれ、保存済みのチャンクと照合されます。Knowledge の検索プレイグラウンドでは、全文検索・ベクトル・ハイブリッドを切り替えて結果を比べられます。

ダッシュボードには、起動時にモデルがベクトルを返したことを確かめてから「準備完了」と表示され、利用しているアプリとして Knowledge が並びます。新しいバージョンを自動で入れるか、バージョンを固定して都合のよいときに更新するかを選べます。開発者向けには、768 次元のベクトルを返す埋め込み API も用意しています。

Embedding はプロジェクトの中で動き、モデルもアプリに含まれています。API キーは不要で、外部のサービスを呼び出さないため、文書の本文がプロジェクトの外に出ることはありません。CPU で動作し、GPU ノードは必要ありません。アクセスには、組織のアカウントによるプロジェクトのサインインを使います。Knowledge をインストールすると、Embedding も自動でインストールされます。
highlights:
- screenshot: installation
locales:
en:
title: Runs inside the Project
body: The model ships with the app, with no API key and no outside service, so document text stays in the Project. The Dashboard marks it Ready once the model has answered, and shows Knowledge as the app that uses it.
ja:
title: プロジェクトの中で動きます
body: モデルはアプリに含まれ、API キーも外部サービスも使わないため、文書の本文はプロジェクトの中にとどまります。モデルが応答してからダッシュボードに「準備完了」と表示され、利用しているアプリとして Knowledge が並びます。
- screenshot: knowledge-vector-search
locales:
en:
title: Search by meaning in Knowledge
body: Vector and hybrid search in Knowledge rely on Embedding, so a question finds relevant passages even when the document uses other words. The search playground lets you compare full-text, vector and hybrid results for the same query.
ja:
title: Knowledge で意味の近さから探せます
body: Knowledge のベクトル検索とハイブリッド検索は Embedding を使います。文書と言い回しが違う質問でも、関係する箇所が見つかります。検索プレイグラウンドでは、同じクエリで全文検索・ベクトル・ハイブリッドの結果を比べられます。
- screenshot: catalog-requires
locales:
en:
title: Installed together with Knowledge
body: Knowledge lists Embedding as a required app and installs it automatically. There is nothing else to install or configure, and you can let new versions arrive automatically or pin a version.
ja:
title: Knowledge と一緒に入ります
body: Knowledge は必要なアプリとして Embedding を挙げており、インストール時に自動で入ります。ほかに入れるものや設定はありません。新しいバージョンを自動で反映するか、固定するかも選べます。
screenshots:
- name: installation
file: installation.webp
alt:
en: "AppThrust Dashboard page for the installed Embedding app, version 0.2.0, with Ready and Healthy badges, the branch and update settings, and a Dependencies card listing Knowledge as the app that uses it."
ja: "AppThrust ダッシュボードのインストール済み Embedding(0.2.0)のページ。「準備完了」「正常」のバッジ、ブランチと更新の設定、利用しているアプリとして Knowledge を示す依存関係カードが表示されています。"
- name: knowledge-vector-search
file: knowledge-vector-search.webp
alt:
en: "Knowledge search playground with the query 「育児休業から復帰するときの手続き」 entered, search mode set to Vector, maximum hits 8, and options to rerank or expand the query with an LLM."
ja: "Knowledge の検索プレイグラウンド。クエリに「育児休業から復帰するときの手続き」を入力し、検索モードを「ベクトル」、最大ヒット数を 8 にした状態で、LLM による並べ替えとクエリ補完の選択肢があります。"
- name: catalog-requires
file: catalog-requires.webp
alt:
en: "Dashboard Marketplace catalog cards for AI Gateway, Embedding, Inference, Knowledge, LLM and Vision; the Knowledge card lists Embedding and AI Gateway as required apps that install automatically."
ja: "ダッシュボードのマーケットプレイスのカタログ。AI Gateway、Embedding、Inference、Knowledge、LLM、Vision のカードが並び、Knowledge のカードには必要なアプリとして Embedding と AI Gateway(自動でインストール)が表示されています。"
Binary file added catalog/screenshots/catalog-requires.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added catalog/screenshots/installation.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added catalog/screenshots/knowledge-vector-search.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/appthrust/embedding
go 1.26.0

require (
github.com/appthrust/appserver-go v0.1.0
github.com/appthrust/appserver-go v0.3.0
github.com/stretchr/testify v1.11.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/appthrust/appserver-go v0.1.0 h1:MYpkwwm4wqa+YcKe1AwywcRe9xuUtTooK4+o7Z5Jbqo=
github.com/appthrust/appserver-go v0.1.0/go.mod h1:0KSf9RQZ6OxBcE0lxYzzjKF37nfwbKps3wXUGlE0oFo=
github.com/appthrust/appserver-go v0.3.0 h1:zxOz0hkspZSXjLq3KWGDLkZIz42Jag6wqRujZ8lTru0=
github.com/appthrust/appserver-go v0.3.0/go.mod h1:0KSf9RQZ6OxBcE0lxYzzjKF37nfwbKps3wXUGlE0oFo=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
Expand Down
130 changes: 130 additions & 0 deletions hack/catalog-listing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { describe, expect, test } from 'bun:test'
import { createHash } from 'node:crypto'
import { mkdtemp, mkdir, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { imageDimensions, loadListing, uploadMedia, validateListing, type Listing } from './catalog-listing'
import { renderEntry, renderListingUpdate, type CatalogEntry } from './publish-entry'

/** Minimal valid PNG: 8-byte signature + IHDR chunk; dimensions only, no pixel data. */
function png(width: number, height: number): Uint8Array {
const bytes = new Uint8Array(33)
bytes.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], 0)
const view = new DataView(bytes.buffer)
view.setUint32(8, 13)
bytes.set([0x49, 0x48, 0x44, 0x52], 12)
view.setUint32(16, width)
view.setUint32(20, height)
return bytes
}

function webpVP8X(width: number, height: number): Uint8Array {
const bytes = new Uint8Array(30)
bytes.set([0x52, 0x49, 0x46, 0x46], 0)
bytes.set([0x57, 0x45, 0x42, 0x50], 8)
bytes.set([0x56, 0x50, 0x38, 0x58], 12)
const w = width - 1, h = height - 1
bytes.set([w & 0xff, (w >> 8) & 0xff, (w >> 16) & 0xff], 24)
bytes.set([h & 0xff, (h >> 8) & 0xff, (h >> 16) & 0xff], 27)
return bytes
}

const listing: Listing = {
locales: {
en: { tagline: 'People, groups and profiles.', overview: 'Who is who.\n\nSearch and browse.' },
ja: { tagline: 'この組織のメンバー、グループ、プロフィール。', overview: '誰が誰か。' },
},
highlights: [{ locales: { en: { title: 'Search' }, ja: { title: '検索' } }, screenshot: 'people' }],
screenshots: [{
name: 'people', digest: `sha256:${'a'.repeat(64)}`, mediaType: 'image/png', size: 33, width: 1280, height: 800,
alt: { en: 'People list', ja: 'メンバー一覧' },
}],
}

describe('imageDimensions', () => {
test('reads PNG IHDR and WebP VP8X', () => {
expect(imageDimensions(png(1280, 800))).toEqual({ mediaType: 'image/png', width: 1280, height: 800 })
expect(imageDimensions(webpVP8X(1440, 900))).toEqual({ mediaType: 'image/webp', width: 1440, height: 900 })
expect(() => imageDimensions(new Uint8Array(40))).toThrow('PNG or WebP')
})
})

describe('validateListing', () => {
test('accepts the sample and enforces the contract', () => {
expect(() => validateListing(listing)).not.toThrow()
expect(() => validateListing({ locales: { ja: { tagline: 'x' } } })).toThrow('requires the "en" locale')
expect(() => validateListing({ ...listing, highlights: [{ locales: { en: { title: 'x' } }, screenshot: 'missing' }] }))
.toThrow('unknown screenshot "missing"')
expect(() => validateListing({ ...listing, screenshots: [{ ...listing.screenshots![0], size: 600_000 }] })).toThrow('bytes')
expect(() => validateListing({ ...listing, screenshots: [{ ...listing.screenshots![0], alt: { ja: 'x' } }] })).toThrow('requires the "en" locale')
expect(() => validateListing({ locales: { en: { tagline: 'x'.repeat(201) } } })).toThrow('exceeds 200')
})
})

describe('loadListing', () => {
test('resolves screenshot files to digests, sizes and dimensions', async () => {
const dir = await mkdtemp(join(tmpdir(), 'listing-'))
await mkdir(join(dir, 'screenshots'))
const image = png(1200, 750)
await writeFile(join(dir, 'screenshots', 'people.png'), image)
await writeFile(join(dir, 'listing.yaml'), [
'locales:', ' en: { tagline: People, groups and profiles. }', ' ja: { tagline: メンバー一覧 }',
'highlights:', ' - screenshot: people', ' locales: { en: { title: Search }, ja: { title: 検索 } }',
'screenshots:', ' - name: people', ' file: people.png', ' alt: { en: People list, ja: メンバー一覧 }',
].join('\n'))
const { listing: loaded, media } = await loadListing(pathToFileURL(`${dir}/`))
const digest = `sha256:${createHash('sha256').update(image).digest('hex')}`
expect(media).toHaveLength(1)
expect(media[0].bytes).toEqual(image)
expect(loaded.screenshots).toEqual([{ name: 'people', digest, mediaType: 'image/png', size: 33, width: 1200, height: 750, alt: { en: 'People list', ja: 'メンバー一覧' } }])
expect(loaded.highlights?.[0].screenshot).toBe('people')
})

test('rejects paths escaping catalog/screenshots', async () => {
const dir = await mkdtemp(join(tmpdir(), 'listing-'))
await writeFile(join(dir, 'listing.yaml'), 'locales: { en: { tagline: x } }\nscreenshots: [{ name: a, file: ../x.png, alt: { en: a } }]\n')
await expect(loadListing(pathToFileURL(`${dir}/`))).rejects.toThrow('relative path')
})
})

describe('uploadMedia', () => {
test('PUTs each blob by hex digest and checks the stored descriptor', async () => {
const image = png(10, 10)
const digest = `sha256:${createHash('sha256').update(image).digest('hex')}`
const calls: Array<{ url: string; type: string }> = []
const fetcher = async (url: string, init: RequestInit): Promise<Response> => {
calls.push({ url, type: (init.headers as Record<string, string>)['content-type'] })
return Response.json({ digest, mediaType: 'image/png', size: 33 })
}
await uploadMedia([{ ...listing.screenshots![0], digest, bytes: image }], 'https://api.example', 'token', fetcher)
expect(calls).toEqual([{ url: `https://api.example/api/v1/catalog/media/${digest.slice(7)}`, type: 'image/png' }])
const mismatch = async (): Promise<Response> => Response.json({ digest, mediaType: 'image/png', size: 1 })
await expect(uploadMedia([{ ...listing.screenshots![0], digest, bytes: image }], 'https://api.example', 'token', mismatch))
.rejects.toThrow('does not match')
})
})

describe('listing in entries', () => {
const template = [
'apiVersion: appthrust.io/v1alpha1', 'kind: ApplicationStackDefinition', 'metadata: { name: embedding }',
'spec:', ' display: { title: Directory, description: People., category: collaborate, iconRef: { name: embedding } }',
' versions: []', ' updatePolicy: { default: pinned, allowed: [pinned, follow] }',
].join('\n')
const digest = `sha256:${'b'.repeat(64)}`

test('renderEntry carries the authored listing and otherwise preserves the stored one', () => {
const first = renderEntry(template, '0.2.0', digest, undefined, listing)
expect(first.listing).toEqual(listing)
const next = renderEntry(template, '0.2.1', `sha256:${'c'.repeat(64)}`, first)
expect(next.listing).toEqual(listing)
expect(renderEntry(template, '0.2.0', digest).listing).toBeUndefined()
})

test('renderListingUpdate replaces only the listing', () => {
const current: CatalogEntry = { ...renderEntry(template, '0.2.0', digest), publishedAt: '2026-11-01T00:00:00Z' }
const updated = renderListingUpdate(current, listing)
expect(updated).toEqual({ ...current, listing })
expect(() => renderListingUpdate({ ...current, slug: 'other' }, listing)).toThrow('slug embedding')
})
})
Loading