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) andbase64_binaryfor efficient storage and retrieval. - Compatible with Perplexity's
pplx-embed-v1-0.6bandpplx-embed-v1-4bmodels. - The model must match the one used in the corresponding
PerplexityDocumentEmbedderin the indexing pipeline.
Configuration
- Drag the
PerplexityTextEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Create a secret with your Perplexity API key. Use
PERPLEXITY_API_KEYas the secret key. For instructions, see Create Secrets. Get your API key from Perplexity AI. - Select the same embedding model you used for indexing. Available models are listed in the Perplexity Embeddings API reference.
- Create a secret with your Perplexity API key. Use
- Go to the Advanced tab to configure
encoding_formatandtimeout.
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
| Parameter | Type | Description |
|---|---|---|
text | str | The text to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
embedding | List[float] | The embedding of the input text. |
meta | Dict[str, Any] | Metadata about the request, including model name and usage statistics. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Secret | Secret.from_env_var('PERPLEXITY_API_KEY') | The Perplexity API key. |
model | str | pplx-embed-v1-0.6b | The Perplexity embedding model to use. See Perplexity Embeddings API reference for available models. |
api_base_url | Optional[str] | https://api.perplexity.ai/v1 | The Perplexity API base URL. |
prefix | str | "" | A string to add to the beginning of the text. |
suffix | str | "" | A string to add to the end of the text. |
encoding_format | str | base64_int8 | The embedding encoding format. Supported values: base64_int8 and base64_binary. |
timeout | Optional[float] | None | Timeout for API calls in seconds. Defaults to the OPENAI_TIMEOUT environment variable or 30 seconds. |
max_retries | Optional[int] | None | Maximum number of retries after an internal error. Defaults to the OPENAI_MAX_RETRIES environment variable or 5. |
http_client_kwargs | Optional[Dict[str, Any]] | None | Keyword 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.
| Parameter | Type | Description |
|---|---|---|
text | str | The text to embed. |
Related Information
Was this page helpful?