Skip to content
Draft
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
34 changes: 32 additions & 2 deletions apps/docs/content/docs/integrations/embeddings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ReferenceDetails } from "@/components/ui/reference-details"
{/* MANUAL-CONTENT-START:intro */}
An embedding represents text as a numeric vector. Compare vectors to search by meaning, group related text, or find near-duplicates.

The Embeddings block accepts a string or list of strings and returns one vector per input in the same order. Choose OpenAI, Google Gemini, Cohere, Mistral, OpenRouter, or an embedding model on your Ollama server. Dimension and task-type controls appear only for supported models.
The Embeddings block accepts a string or list of strings and returns one vector per input in the same order. Choose OpenAI, Google Gemini, Cohere, Mistral, Perplexity, OpenRouter, or an embedding model on your Ollama server. Dimension and task-type controls appear only for supported models.

## Input and model limits

Expand All @@ -35,7 +35,7 @@ Knowledge bases embed separately. Each base fixes an embedding model and vector

## Use the block [#usage-instructions]

Turn text into embedding vectors for semantic search, clustering, and similarity. Supports OpenAI, OpenRouter, Google Gemini, Cohere, and Mistral embedding models, plus embedding models on a self-hosted Ollama.
Turn text into embedding vectors for semantic search, clustering, and similarity. Supports OpenAI, OpenRouter, Google Gemini, Cohere, Mistral, and Perplexity embedding models, plus embedding models on a self-hosted Ollama.

## Actions

Expand Down Expand Up @@ -189,6 +189,36 @@ Generate embeddings from text using Mistral's embedding models

</ReferenceDetails>

### Perplexity Embeddings

Generate embeddings from text using Perplexity's embedding models

<ReferenceDetails>

#### Input

| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `input` | string | Yes | Text to embed, or an array of texts to embed in one call |
| `model` | string | No | Embedding model to use |
| `taskType` | string | No | What the embedding is for, when the model supports task conditioning: document, query, similarity, classification, or clustering |
| `dimensions` | number | No | Output dimensions, when the model supports truncation. Defaults to native. |
| `apiKey` | string | Yes | API key for the selected embedding provider |

#### Output

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `embeddings` | json | Generated embedding vectors, one per input, in input order |
| `model` | string | Model used |
| `provider` | string | Provider used |
| `dimensions` | number | Dimensionality of each returned vector |
| `usage` | json | Token usage |
| ↳ `prompt_tokens` | number | Tokens in the input |
| ↳ `total_tokens` | number | Total tokens billed |

</ReferenceDetails>

### Ollama Embeddings

Generate embeddings on a self-hosted Ollama server
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/blocks/blocks/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const TOOL_ID_BY_PROVIDER: Record<EmbeddingBlockProvider, string> = {
gemini: 'embeddings_gemini',
cohere: 'embeddings_cohere',
mistral: 'embeddings_mistral',
perplexity: 'embeddings_perplexity',
ollama: 'embeddings_ollama',
}

Expand All @@ -42,6 +43,7 @@ const PROVIDER_LABELS: Record<EmbeddingBlockProvider, string> = {
gemini: 'Google Gemini',
cohere: 'Cohere',
mistral: 'Mistral',
perplexity: 'Perplexity',
ollama: 'Ollama',
}

Expand Down Expand Up @@ -164,7 +166,7 @@ export const EmbeddingsBlock: BlockConfig = {
description: 'Generate embeddings',
authMode: AuthMode.ApiKey,
longDescription:
'Turn text into embedding vectors for semantic search, clustering, and similarity. Supports OpenAI, OpenRouter, Google Gemini, Cohere, and Mistral embedding models, plus embedding models on a self-hosted Ollama.',
'Turn text into embedding vectors for semantic search, clustering, and similarity. Supports OpenAI, OpenRouter, Google Gemini, Cohere, Mistral, and Perplexity embedding models, plus embedding models on a self-hosted Ollama.',
category: 'tools',
integrationType: IntegrationType.AI,
docsLink: 'https://docs.sim.ai/integrations/embeddings',
Expand Down Expand Up @@ -237,6 +239,7 @@ export const EmbeddingsBlock: BlockConfig = {
'embeddings_gemini',
'embeddings_cohere',
'embeddings_mistral',
'embeddings_perplexity',
'embeddings_ollama',
],
config: {
Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/core/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export const env = createEnv({
OPENAI_API_KEY_3: z.string().min(1).optional(), // Additional OpenAI API key for load balancing
OPENROUTER_API_KEY: z.string().min(1).optional(), // OpenRouter API key; self-hosted fallback for OpenAI knowledge-base embeddings
MISTRAL_API_KEY: z.string().min(1).optional(), // Mistral AI API key
PERPLEXITY_API_KEY: z.string().min(1).optional(), // Perplexity API key
ANTHROPIC_API_KEY_1: z.string().min(1).optional(), // Primary Anthropic Claude API key
ANTHROPIC_API_KEY_2: z.string().min(1).optional(), // Additional Anthropic API key for load balancing
ANTHROPIC_API_KEY_3: z.string().min(1).optional(), // Additional Anthropic API key for load balancing
Expand Down
31 changes: 30 additions & 1 deletion apps/sim/lib/embeddings/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export function isKbEmbeddingDimensions(value: number): value is KbEmbeddingDime
*/
const OPENAI_MAX_TOKENS_PER_REQUEST = 300_000

/** Perplexity caps a single `/v1/embeddings` call at 120,000 tokens across all inputs. */
const PERPLEXITY_MAX_TOKENS_PER_REQUEST = 120_000

export interface EmbeddingModelInfo {
provider: EmbeddingCatalogProvider
/** Human-readable label for the block's model dropdown. */
Expand Down Expand Up @@ -179,6 +182,29 @@ export const EMBEDDING_MODELS: Record<string, EmbeddingModelInfo> = {
maxInputTokens: 8192,
kbEligible: false,
},
/** Perplexity accepts any `dimensions` from 128 up to the native size. */
'pplx-embed-v1-0.6b': {
provider: 'perplexity',
label: 'pplx-embed-v1-0.6b',
pricingId: 'pplx-embed-v1-0.6b',
tokenizerProvider: 'perplexity',
nativeDimensions: 1024,
supportedDimensions: [1024, 768, 512, 384, 256, 128],
maxInputTokens: 32_000,
maxTokensPerRequest: PERPLEXITY_MAX_TOKENS_PER_REQUEST,
kbEligible: false,
},
'pplx-embed-v1-4b': {
provider: 'perplexity',
label: 'pplx-embed-v1-4b',
pricingId: 'pplx-embed-v1-4b',
tokenizerProvider: 'perplexity',
nativeDimensions: 2560,
supportedDimensions: [2560, 2048, 1536, 1024, 768, 512, 384, 256, 128],
maxInputTokens: 32_000,
maxTokensPerRequest: PERPLEXITY_MAX_TOKENS_PER_REQUEST,
kbEligible: false,
},
}

/**
Expand All @@ -192,6 +218,7 @@ export const EMBEDDING_CATALOG_PROVIDERS: readonly KeyedEmbeddingProvider[] = [
'gemini',
'cohere',
'mistral',
'perplexity',
] as const

/**
Expand All @@ -203,6 +230,7 @@ export const DEFAULT_MODEL_BY_PROVIDER: Record<KeyedEmbeddingProvider, string> =
gemini: 'gemini-embedding-001',
cohere: 'embed-v4.0',
mistral: 'mistral-embed',
perplexity: 'pplx-embed-v1-4b',
}

/**
Expand All @@ -214,6 +242,7 @@ export const BYOK_PROVIDER_IDS: Record<KeyedEmbeddingProvider, BYOKProviderId> =
gemini: 'google',
cohere: 'cohere',
mistral: 'mistral',
perplexity: 'perplexity',
}

/**
Expand Down Expand Up @@ -326,7 +355,7 @@ export function getKbEmbeddingDimensions(info: EmbeddingModelInfo): KbEmbeddingD
* True when a model's tokens cannot be counted exactly.
*
* Batching measures with tiktoken, which only has encodings for OpenAI models —
* every other id falls back to `cl100k_base`, so Gemini, Cohere, and Mistral
* every other id falls back to `cl100k_base`, so Gemini, Cohere, Mistral, and Perplexity
* ceilings are enforced in approximate units. The ceiling is still applied as
* declared rather than discounted to absorb the error: an undercount surfaces
* as a visible provider rejection, whereas silently shortening an embedding's
Expand Down
4 changes: 4 additions & 0 deletions apps/sim/lib/embeddings/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const PROVIDER_KEY_CONFIG: Record<KeyedEmbeddingProvider, () => ProviderKeyConfi
byokProviderId: BYOK_PROVIDER_IDS.mistral,
envKey: env.MISTRAL_API_KEY,
}),
perplexity: () => ({
byokProviderId: BYOK_PROVIDER_IDS.perplexity,
envKey: env.PERPLEXITY_API_KEY,
}),
}

export async function resolveProviderKey(
Expand Down
3 changes: 3 additions & 0 deletions apps/sim/lib/embeddings/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createMistralAdapter } from '@/lib/embeddings/providers/mistral'
import { createOllamaAdapter } from '@/lib/embeddings/providers/ollama'
import { createOpenAIAdapter } from '@/lib/embeddings/providers/openai'
import { createOpenRouterAdapter } from '@/lib/embeddings/providers/openrouter'
import { createPerplexityAdapter } from '@/lib/embeddings/providers/perplexity'
import type {
AzureEmbeddingAdapterContext,
EmbeddingAdapterFactory,
Expand All @@ -30,6 +31,7 @@ const ADAPTER_FACTORIES: { [K in EmbeddingProviderKind]: AdapterFactoryFor<K> }
gemini: createGeminiAdapter,
cohere: createCohereAdapter,
mistral: createMistralAdapter,
perplexity: createPerplexityAdapter,
ollama: createOllamaAdapter,
}

Expand All @@ -47,4 +49,5 @@ export {
createOllamaAdapter,
createOpenAIAdapter,
createOpenRouterAdapter,
createPerplexityAdapter,
}
46 changes: 46 additions & 0 deletions apps/sim/lib/embeddings/providers/perplexity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { l2Normalize } from '@/lib/embeddings/normalize'
import type { EmbeddingAdapterFactory } from '@/lib/embeddings/types'

/** Perplexity's embeddings endpoint accepts at most 512 inputs per request. */
const PERPLEXITY_MAX_ITEMS_PER_REQUEST = 512

interface PerplexityEmbeddingResponse {
data: Array<{ embedding: string; index: number }>
usage?: { prompt_tokens?: number; total_tokens?: number }
}

/**
* Perplexity `/v1/embeddings`. The API has no float encoding: `base64_int8`
* returns each vector as base64-encoded signed int8 values, so they are decoded
* here and L2-normalized to match the unit vectors other providers return.
* Normalizing keeps cosine similarity unchanged and makes inner product match
* it. Perplexity has no task conditioning for these models, so `taskType` is
* ignored.
*/
export const createPerplexityAdapter: EmbeddingAdapterFactory = ({ modelName, apiKey }) => ({
maxItemsPerRequest: PERPLEXITY_MAX_ITEMS_PER_REQUEST,
buildRequest: ({ inputs, dimensions }) => ({
apiUrl: 'https://api.perplexity.ai/v1/embeddings',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
'User-Agent': 'Sim/1.0 (+https://sim.ai)',
'X-Pplx-Integration': 'sim',
},
body: {
model: modelName,
input: inputs,
encoding_format: 'base64_int8',
...(dimensions !== undefined && { dimensions }),
},
parse: (json) => {
const { data } = json as PerplexityEmbeddingResponse
return [...data]
.sort((a, b) => a.index - b.index)
.map((item) =>
l2Normalize(Array.from(new Int8Array(Buffer.from(item.embedding, 'base64'))))
)
},
parseTokens: (json) => (json as PerplexityEmbeddingResponse).usage?.total_tokens,
}),
})
39 changes: 39 additions & 0 deletions apps/sim/lib/embeddings/providers/providers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createGeminiAdapter,
createMistralAdapter,
createOllamaAdapter,
createPerplexityAdapter,
} from '@/lib/embeddings/providers'

const INPUTS = ['alpha', 'beta']
Expand Down Expand Up @@ -82,6 +83,44 @@ describe('Mistral adapter', () => {
})
})

describe('Perplexity adapter', () => {
const adapter = createPerplexityAdapter({
modelName: 'pplx-embed-v1-4b',
apiKey: 'pplx-test',
nativeDimensions: 2560,
})

it('requests int8 output and forwards a reduced dimension', () => {
const request = adapter.buildRequest({ inputs: INPUTS, taskType: 'query', dimensions: 1024 })
expect(request.body).toEqual({
model: 'pplx-embed-v1-4b',
input: INPUTS,
encoding_format: 'base64_int8',
dimensions: 1024,
})
expect(request.headers).toMatchObject({
'User-Agent': 'Sim/1.0 (+https://sim.ai)',
'X-Pplx-Integration': 'sim',
})
})

it('decodes signed int8 vectors to unit vectors in input order', () => {
const request = adapter.buildRequest({ inputs: INPUTS, taskType: 'document' })
const json = {
data: [
{ embedding: Buffer.from(Int8Array.of(0, -4)).toString('base64'), index: 1 },
{ embedding: Buffer.from(Int8Array.of(3, 4)).toString('base64'), index: 0 },
],
usage: { total_tokens: 4 },
}
expect(request.parse(json)).toEqual([
[0.6, 0.8],
[0, -1],
])
expect(request.parseTokens?.(json)).toBe(4)
})
})

describe('Ollama adapter', () => {
const adapter = createOllamaAdapter({
modelName: 'nomic-embed-text',
Expand Down
9 changes: 8 additions & 1 deletion apps/sim/lib/embeddings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type EmbeddingProviderKind =
| 'gemini'
| 'cohere'
| 'mistral'
| 'perplexity'
| 'ollama'

/**
Expand All @@ -27,7 +28,13 @@ export type EmbeddingCatalogProvider = Exclude<EmbeddingProviderKind, 'azure-ope
export type KeyedEmbeddingProvider = Exclude<EmbeddingCatalogProvider, 'ollama'>

/** Provider id for `estimateTokenCount` so token counts match the embedding provider's tokenization. */
export type TokenizerProviderId = 'openai' | 'google' | 'cohere' | 'mistral' | 'ollama'
export type TokenizerProviderId =
| 'openai'
| 'google'
| 'cohere'
| 'mistral'
| 'perplexity'
| 'ollama'

/**
* What the embedding will be used for. Providers that support task-conditioned
Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/internal/embeddings/execute-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const PROVIDERS_BY_TOOL_ID: Record<string, EmbeddingProvider> = {
embeddings_gemini: 'gemini',
embeddings_cohere: 'cohere',
embeddings_mistral: 'mistral',
embeddings_perplexity: 'perplexity',
embeddings_ollama: 'ollama',
}

Expand Down
2 changes: 2 additions & 0 deletions apps/sim/lib/internal/embeddings/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const embeddingProviders = [
'gemini',
'cohere',
'mistral',
'perplexity',
'ollama',
] as const satisfies readonly EmbeddingToolProvider[]

Expand Down Expand Up @@ -53,6 +54,7 @@ const catalogProviders = [
'gemini',
'cohere',
'mistral',
'perplexity',
] as const satisfies readonly EmbeddingCatalogProvider[]

export const embeddingsInputSchema = z.discriminatedUnion('provider', [
Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/internal/tool-operations/registry.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ const EMBEDDINGS_TOOL_IDS = [
'embeddings_gemini',
'embeddings_cohere',
'embeddings_mistral',
'embeddings_perplexity',
'embeddings_ollama',
'openai_embeddings',
] as const
Expand Down
10 changes: 10 additions & 0 deletions apps/sim/providers/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6694,6 +6694,16 @@ export const EMBEDDING_MODEL_PRICING: Record<string, ModelPricing> = {
output: 0.0,
updatedAt: '2026-08-05',
},
'pplx-embed-v1-0.6b': {
input: 0.004, // $0.004 per 1M tokens
output: 0.0,
updatedAt: '2026-11-09',
},
'pplx-embed-v1-4b': {
input: 0.03, // $0.03 per 1M tokens
output: 0.0,
updatedAt: '2026-11-09',
},
}

export function getEmbeddingModelPricing(modelId: string): ModelPricing | null {
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/tools/embeddings/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { embeddingsGeminiTool } from '@/tools/embeddings/gemini'
import { embeddingsMistralTool } from '@/tools/embeddings/mistral'
import { embeddingsOpenAITool } from '@/tools/embeddings/openai'
import { embeddingsOpenRouterTool } from '@/tools/embeddings/openrouter'
import { embeddingsPerplexityTool } from '@/tools/embeddings/perplexity'
import { embeddingsTool as legacyOpenAIEmbeddingsTool } from '@/tools/openai/embeddings'

const ALL_TOOLS = [
Expand All @@ -12,6 +13,7 @@ const ALL_TOOLS = [
embeddingsCohereTool,
embeddingsMistralTool,
embeddingsOpenRouterTool,
embeddingsPerplexityTool,
legacyOpenAIEmbeddingsTool,
]

Expand Down
1 change: 1 addition & 0 deletions apps/sim/tools/embeddings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export { embeddingsMistralTool } from '@/tools/embeddings/mistral'
export { embeddingsOllamaTool } from '@/tools/embeddings/ollama'
export { embeddingsOpenAITool } from '@/tools/embeddings/openai'
export { embeddingsOpenRouterTool } from '@/tools/embeddings/openrouter'
export { embeddingsPerplexityTool } from '@/tools/embeddings/perplexity'
export type { EmbeddingsParams, EmbeddingsResponse } from '@/tools/embeddings/types'
Loading