Embedding Trace Logger (src/trace-embedding.ts)

giselle · analytics, langfuse, embedding, tracing, metrics

Sends embedding operation metrics to Langfuse, constructing tags and metadata for observability of AI embeddings.

// Source: https://github.com/mperkins0155/giselle | License: Apache-2.0 | Copyright 2024 ROUTE06, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import { calculateEmbeddingDisplayCost } from "@giselles-ai/language-model";
import type { EmbeddingMetrics } from "@giselles-ai/rag";
import { Langfuse } from "langfuse";

function buildTags(args: {
	provider: "openai" | "google";
	dimensions: number;
	operation: "embed" | "embedMany";
}) {
	return [
		`provider:${args.provider}`,
		`embedding-dimensions:${args.dimensions}`,
		`embedding-operation:${args.operation}`,
	];
}

export async function traceEmbedding(args: {
	metrics: EmbeddingMetrics;
	userId?: string;
	sessionId?: string;
	tags?: string[];
	metadata?: Record<string, unknown>;
}) {
	const {
		texts,
		model,
		op

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key