MCPcopy Index your code
hub / github.com/simstudioai/sim / recordSearchEmbeddingUsage

Function recordSearchEmbeddingUsage

apps/sim/lib/knowledge/embeddings.ts:418–451  ·  view source on GitHub ↗
(params: {
  userId: string
  workspaceId?: string | null
  embeddingModel: string
  query: string
  isBYOK: boolean
  sourceReference: string
})

Source from the content-addressed store, hash-verified

416 * there is no workspace to attribute to. Best-effort: never throws.
417 */
418export async function recordSearchEmbeddingUsage(params: {
419 userId: string
420 workspaceId?: string | null
421 embeddingModel: string
422 query: string
423 isBYOK: boolean
424 sourceReference: string
425}): Promise<void> {
426 const { userId, workspaceId, embeddingModel, query, isBYOK, sourceReference } = params
427 if (isBYOK || !workspaceId) return
428 try {
429 const { count } = estimateTokenCount(
430 query,
431 getEmbeddingModelInfo(embeddingModel).tokenizerProvider
432 )
433 const cost = calculateCost(embeddingModel, count, 0, false)
434 if (!cost || cost.total <= 0) return
435 await recordUsage({
436 userId,
437 workspaceId,
438 entries: [
439 {
440 category: 'model',
441 source: 'knowledge-base',
442 description: embeddingModel,
443 cost: cost.total,
444 sourceReference,
445 },
446 ],
447 })
448 } catch (error) {
449 logger.warn('Failed to record search embedding usage', { error: getErrorMessage(error) })
450 }
451}

Callers 2

executeFunction · 0.90
route.tsFile · 0.90

Calls 6

estimateTokenCountFunction · 0.90
getEmbeddingModelInfoFunction · 0.90
calculateCostFunction · 0.90
recordUsageFunction · 0.90
getErrorMessageFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected