mirror of
https://github.com/simstudioai/sim.git
synced 2026-11-30 02:47:16 +08:00
* feat(docs): rebuild documentation with the Paper design system * fix(docs): verify nested tabs and fresh-checkout CI setup * chore(docs): refresh preservation evidence against latest staging * fix(docs): align shared navigation and controls with Paper * fix(docs): share active heading across responsive outlines * fix(docs): track the final section at the end of the page * fix(docs): preserve sidebar scroll in a persistent layout * fix(docs): restore live screenshot backgrounds and framing * fix(docs): finish layout polish and clean implementation references * fix(docs): align shared dark theme and overlay states * fix(docs): remove dark borders from platform screenshots * test(docs): benchmark production navigation and image delivery in CI * fix(docs): preserve machine content and production reading contracts * fix(docs): retain readable tabs without JavaScript and verify current staging * fix(docs): expose root response schemas and generate clean-checkout types * fix(docs): resolve no-script tabs in the preflight cascade layer * perf(docs): import only the search schema constructors * fix(docs): preserve retrieval excerpts and reduce reading overhead * fix(docs): reuse in-flight intent prefetches during navigation * docs: record production readiness evidence and release requirements * docs: clarify optimizer measurement provenance * docs: preserve latest staging Search assets and compatibility evidence * fix(docs): polish responsive controls and keep search indexing current * test(docs): select the visible API example in browser checks * test(docs): execute native examples against streaming and binary responses * fix(docs): stream native API responses without buffering * test(docs): cover review regressions through public interfaces * fix(docs): preserve accessible examples and gate index publication * fix(docs): finish accessible controls and cached content validation * fix(docs): validate integration parents and report partial search failures * fix(docs): refine navigation and compact sample controls * fix(docs): isolate synchronous corpus validation from HTTP readers * fix(docs): restore Paper interaction styling and verify responsive controls * fix(docs): score each search page once per retrieval source * fix(docs): attribute benchmark metrics to their source document --------- Co-authored-by: Waleed Latif <walif6@gmail.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
const EMBEDDING_TIMEOUT_MS = 1500
|
|
const embeddingResponse = z.object({
|
|
data: z.array(z.object({ embedding: z.array(z.number().finite()).length(1536) })).min(1),
|
|
})
|
|
|
|
/** Generates the fixed-width vector used by the optional public docs index. */
|
|
export async function generateSearchEmbedding(
|
|
query: string,
|
|
signal?: AbortSignal
|
|
): Promise<number[]> {
|
|
const apiKey = process.env.OPENAI_API_KEY
|
|
if (!apiKey) throw new Error('OPENAI_API_KEY is required for semantic search')
|
|
const timeout = AbortSignal.timeout(EMBEDDING_TIMEOUT_MS)
|
|
const response = await fetch('https://api.openai.com/v1/embeddings', {
|
|
method: 'POST',
|
|
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
input: query,
|
|
model: 'text-embedding-3-small',
|
|
encoding_format: 'float',
|
|
}),
|
|
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
})
|
|
if (!response.ok) throw new Error(`Embedding provider returned HTTP ${response.status}`)
|
|
const payload = embeddingResponse.parse(await response.json())
|
|
return payload.data[0].embedding
|
|
}
|