Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

PerplexityTextEmbedder

Embed a query string using Perplexity AI embedding models. Use this component in query pipelines to transform user queries into vectors for embedding-based retrieval.

Key Features​

  • Uses Perplexity AI embedding models to produce dense vector representations of text.
  • Outputs a float vector embedding suitable for use with embedding retrievers.
  • Supports two quantized encoding formats: base64_int8 (default) and base64_binary for efficient storage and retrieval.
  • Compatible with Perplexity's pplx-embed-v1-0.6b and pplx-embed-v1-4b models.
  • The model must match the one used in the corresponding PerplexityDocumentEmbedder in the indexing pipeline.

Configuration​

  1. Drag the PerplexityTextEmbedder component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Create a secret with your Perplexity API key. Use PERPLEXITY_API_KEY as the secret key. For instructions, see Create Secrets. Get your API key from Perplexity AI.
    2. Select the same embedding model you used for indexing. Available models are listed in the Perplexity Embeddings API reference.
  4. Go to the Advanced tab to configure encoding_format and timeout.

Connections​

PerplexityTextEmbedder receives the user query as a text string through its text input, typically from the Input component. It outputs a float vector through its embedding output, which you connect to an embedding retriever such as OpenSearchEmbeddingRetriever.

Source Code​

To check this component's source code, open text_embedder.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

PerplexityTextEmbedder:
type: haystack_integrations.components.embedders.perplexity.text_embedder.PerplexityTextEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- PERPLEXITY_API_KEY
strict: false
model: pplx-embed-v1-0.6b
api_base_url: https://api.perplexity.ai/v1
encoding_format: base64_int8

Using the Component in a Pipeline​

This example shows a query pipeline with PerplexityTextEmbedder that embeds the user query and sends it to OpenSearchEmbeddingRetriever to find matching documents.

# haystack-pipeline
components:
PerplexityTextEmbedder:
type: haystack_integrations.components.embedders.perplexity.text_embedder.PerplexityTextEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- PERPLEXITY_API_KEY
strict: false
model: pplx-embed-v1-0.6b
api_base_url: https://api.perplexity.ai/v1
encoding_format: base64_int8
prefix: ""
suffix: ""
OpenSearchEmbeddingRetriever:
type: haystack_integrations.components.retrievers.opensearch.embedding_retriever.OpenSearchEmbeddingRetriever
init_parameters:
filters:
top_k: 10
filter_policy: replace
custom_query:
raise_on_failure: true
efficient_filtering: true
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: Standard-Index-English
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:

connections:
- sender: PerplexityTextEmbedder.embedding
receiver: OpenSearchEmbeddingRetriever.query_embedding

max_runs_per_component: 100

metadata: {}

inputs:
query:
- PerplexityTextEmbedder.text

Parameters​

Inputs​

ParameterTypeDescription
textstrThe text to embed.

Outputs​

ParameterTypeDescription
embeddingList[float]The embedding of the input text.
metaDict[str, Any]Metadata about the request, including model name and usage statistics.

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
api_keySecretSecret.from_env_var('PERPLEXITY_API_KEY')The Perplexity API key.
modelstrpplx-embed-v1-0.6bThe Perplexity embedding model to use. See Perplexity Embeddings API reference for available models.
api_base_urlOptional[str]https://api.perplexity.ai/v1The Perplexity API base URL.
prefixstr""A string to add to the beginning of the text.
suffixstr""A string to add to the end of the text.
encoding_formatstrbase64_int8The embedding encoding format. Supported values: base64_int8 and base64_binary.
timeoutOptional[float]NoneTimeout for API calls in seconds. Defaults to the OPENAI_TIMEOUT environment variable or 30 seconds.
max_retriesOptional[int]NoneMaximum number of retries after an internal error. Defaults to the OPENAI_MAX_RETRIES environment variable or 5.
http_client_kwargsOptional[Dict[str, Any]]NoneKeyword arguments for a custom httpx.Client or httpx.AsyncClient.

Run Method Parameters​

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDescription
textstrThe text to embed.