diff --git a/.release-please-manifest.json b/.release-please-manifest.json index acbe2e7..fc5553b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.23.2" + ".": "0.24.0" } diff --git a/.stats.yml b/.stats.yml index 9ee7c51..f4db3cd 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 6 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-3ee0511fa1bf59b2bb44d947f7d884fd8522ef872d33bab141874941b76f1dd7.yml -openapi_spec_hash: 394bbfe74954625b70de9c85d553e3d0 -config_hash: c7d506cdee510785b58defa1a626e20b +configured_endpoints: 8 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-78325ecc9bdc8e9850866fcdd3be3d209b06f151059c774afc7e6005a1775f09.yml +openapi_spec_hash: 19a34c8ddd46f81dd0b0850af5ee42f3 +config_hash: c3b93f1bb8fa365d5a83e83b7e13e6c4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e8b93..d6a7d3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.24.0 (2026-02-12) + +Full Changelog: [v0.23.2...v0.24.0](https://github.com/perplexityai/perplexity-node/compare/v0.23.2...v0.24.0) + +### Features + +* **api:** Add Embeddings API ([393ccb6](https://github.com/perplexityai/perplexity-node/commit/393ccb6f22165349a70c873f6c260dc756276c1c)) + ## 0.23.2 (2026-02-11) Full Changelog: [v0.23.1...v0.23.2](https://github.com/perplexityai/perplexity-node/compare/v0.23.1...v0.23.2) diff --git a/api.md b/api.md index 2c84497..792f7c7 100644 --- a/api.md +++ b/api.md @@ -6,6 +6,9 @@ Types: - ChatMessageInput - ChatMessageOutput - Choice +- ContextualizedEmbeddingObject +- EmbeddingObject +- EmbeddingsUsage - JsonSchemaFormat - ResponseFormat - SearchResult @@ -55,6 +58,26 @@ Methods: - client.responses.create({ ...params }) -> ResponseCreateResponse +# Embeddings + +Types: + +- EmbeddingCreateResponse + +Methods: + +- client.embeddings.create({ ...params }) -> EmbeddingCreateResponse + +# ContextualizedEmbeddings + +Types: + +- ContextualizedEmbeddingCreateResponse + +Methods: + +- client.contextualizedEmbeddings.create({ ...params }) -> ContextualizedEmbeddingCreateResponse + # Async ## Chat diff --git a/package.json b/package.json index d56210e..fbcbce2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@perplexity-ai/perplexity_ai", - "version": "0.23.2", + "version": "0.24.0", "description": "The official TypeScript library for the Perplexity API", "author": "Perplexity ", "types": "dist/index.d.ts", diff --git a/src/client.ts b/src/client.ts index 6f9a9b2..49feccb 100644 --- a/src/client.ts +++ b/src/client.ts @@ -16,6 +16,12 @@ import * as Errors from './core/error'; import * as Uploads from './core/uploads'; import * as API from './resources/index'; import { APIPromise } from './core/api-promise'; +import { + ContextualizedEmbeddingCreateParams, + ContextualizedEmbeddingCreateResponse, + ContextualizedEmbeddings, +} from './resources/contextualized-embeddings'; +import { EmbeddingCreateParams, EmbeddingCreateResponse, Embeddings } from './resources/embeddings'; import { Annotation, ContentPart, @@ -743,12 +749,16 @@ export class Perplexity { chat: API.Chat = new API.Chat(this); search: API.Search = new API.Search(this); responses: API.Responses = new API.Responses(this); + embeddings: API.Embeddings = new API.Embeddings(this); + contextualizedEmbeddings: API.ContextualizedEmbeddings = new API.ContextualizedEmbeddings(this); async: API.Async = new API.Async(this); } Perplexity.Chat = Chat; Perplexity.Search = Search; Perplexity.Responses = Responses; +Perplexity.Embeddings = Embeddings; +Perplexity.ContextualizedEmbeddings = ContextualizedEmbeddings; Perplexity.Async = Async; export declare namespace Perplexity { @@ -780,12 +790,27 @@ export declare namespace Perplexity { type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming, }; + export { + Embeddings as Embeddings, + type EmbeddingCreateResponse as EmbeddingCreateResponse, + type EmbeddingCreateParams as EmbeddingCreateParams, + }; + + export { + ContextualizedEmbeddings as ContextualizedEmbeddings, + type ContextualizedEmbeddingCreateResponse as ContextualizedEmbeddingCreateResponse, + type ContextualizedEmbeddingCreateParams as ContextualizedEmbeddingCreateParams, + }; + export { Async as Async }; export type APIPublicSearchResult = API.APIPublicSearchResult; export type ChatMessageInput = API.ChatMessageInput; export type ChatMessageOutput = API.ChatMessageOutput; export type Choice = API.Choice; + export type ContextualizedEmbeddingObject = API.ContextualizedEmbeddingObject; + export type EmbeddingObject = API.EmbeddingObject; + export type EmbeddingsUsage = API.EmbeddingsUsage; export type JsonSchemaFormat = API.JsonSchemaFormat; export type ResponseFormat = API.ResponseFormat; export type SearchResult = API.SearchResult; diff --git a/src/resources/contextualized-embeddings.ts b/src/resources/contextualized-embeddings.ts new file mode 100644 index 0000000..231f25a --- /dev/null +++ b/src/resources/contextualized-embeddings.ts @@ -0,0 +1,83 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../core/resource'; +import * as Shared from './shared'; +import { APIPromise } from '../core/api-promise'; +import { RequestOptions } from '../internal/request-options'; + +export class ContextualizedEmbeddings extends APIResource { + /** + * Generate contextualized embeddings for document chunks. Chunks from the same + * document share context awareness, improving retrieval quality for document-based + * applications. + */ + create( + body: ContextualizedEmbeddingCreateParams, + options?: RequestOptions, + ): APIPromise { + return this._client.post('/v1/contextualizedembeddings', { body, ...options }); + } +} + +/** + * Response body for contextualized embeddings request + */ +export interface ContextualizedEmbeddingCreateResponse { + /** + * List of contextualized embedding objects + */ + data?: Array; + + /** + * The model used to generate embeddings + */ + model?: string; + + /** + * The object type + */ + object?: string; + + /** + * Token usage for the embeddings request + */ + usage?: Shared.EmbeddingsUsage; +} + +export interface ContextualizedEmbeddingCreateParams { + /** + * Nested array structure where each inner array contains chunks from a single + * document. Chunks within the same document are encoded with document-level + * context awareness. Maximum 512 documents. Total chunks across all documents must + * not exceed 16,000. Total tokens per document must not exceed 32K. All chunks in + * a single request must not exceed 120,000 tokens combined. Empty strings are not + * allowed. + */ + input: Array>; + + /** + * The contextualized embedding model to use + */ + model: 'pplx-embed-context-v1-0.6b' | 'pplx-embed-context-v1-4b'; + + /** + * Number of dimensions for output embeddings (Matryoshka). Range: 128-1024 for + * pplx-embed-context-v1-0.6b, 128-2560 for pplx-embed-context-v1-4b. Defaults to + * full dimensions (1024 or 2560). + */ + dimensions?: number; + + /** + * Output encoding format for embeddings. base64_int8 returns base64-encoded signed + * int8 values. base64_binary returns base64-encoded packed binary (1 bit per + * dimension). + */ + encoding_format?: 'base64_int8' | 'base64_binary'; +} + +export declare namespace ContextualizedEmbeddings { + export { + type ContextualizedEmbeddingCreateResponse as ContextualizedEmbeddingCreateResponse, + type ContextualizedEmbeddingCreateParams as ContextualizedEmbeddingCreateParams, + }; +} diff --git a/src/resources/embeddings.ts b/src/resources/embeddings.ts new file mode 100644 index 0000000..73abb51 --- /dev/null +++ b/src/resources/embeddings.ts @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../core/resource'; +import * as Shared from './shared'; +import { APIPromise } from '../core/api-promise'; +import { RequestOptions } from '../internal/request-options'; + +export class Embeddings extends APIResource { + /** + * Generate embeddings for a list of texts. Use these embeddings for semantic + * search, clustering, and other machine learning applications. + */ + create(body: EmbeddingCreateParams, options?: RequestOptions): APIPromise { + return this._client.post('/v1/embeddings', { body, ...options }); + } +} + +/** + * Response body for embeddings request + */ +export interface EmbeddingCreateResponse { + /** + * List of embedding objects + */ + data?: Array; + + /** + * The model used to generate embeddings + */ + model?: string; + + /** + * The object type + */ + object?: string; + + /** + * Token usage for the embeddings request + */ + usage?: Shared.EmbeddingsUsage; +} + +export interface EmbeddingCreateParams { + /** + * Input text to embed, encoded as a string or array of strings. Maximum 512 texts + * per request. Each input must not exceed 32K tokens. All inputs in a single + * request must not exceed 120,000 tokens combined. Empty strings are not allowed. + */ + input: string | Array; + + /** + * The embedding model to use + */ + model: 'pplx-embed-v1-0.6b' | 'pplx-embed-v1-4b'; + + /** + * Number of dimensions for output embeddings (Matryoshka). Range: 128-1024 for + * pplx-embed-v1-0.6b, 128-2560 for pplx-embed-v1-4b. Defaults to full dimensions + * (1024 or 2560). + */ + dimensions?: number; + + /** + * Output encoding format for embeddings. base64_int8 returns base64-encoded signed + * int8 values. base64_binary returns base64-encoded packed binary (1 bit per + * dimension). + */ + encoding_format?: 'base64_int8' | 'base64_binary'; +} + +export declare namespace Embeddings { + export { + type EmbeddingCreateResponse as EmbeddingCreateResponse, + type EmbeddingCreateParams as EmbeddingCreateParams, + }; +} diff --git a/src/resources/index.ts b/src/resources/index.ts index 17a23e3..06b373e 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -3,6 +3,12 @@ export * from './shared'; export { Async } from './async/async'; export { Chat, type StreamChunk } from './chat/chat'; +export { + ContextualizedEmbeddings, + type ContextualizedEmbeddingCreateResponse, + type ContextualizedEmbeddingCreateParams, +} from './contextualized-embeddings'; +export { Embeddings, type EmbeddingCreateResponse, type EmbeddingCreateParams } from './embeddings'; export { Responses, type Annotation, diff --git a/src/resources/shared.ts b/src/resources/shared.ts index d0fc2f5..676b664 100644 --- a/src/resources/shared.ts +++ b/src/resources/shared.ts @@ -328,6 +328,90 @@ export interface Choice { finish_reason?: 'stop' | 'length' | null; } +/** + * A single contextualized embedding result + */ +export interface ContextualizedEmbeddingObject { + /** + * List of embedding objects for chunks in this document + */ + data?: Array; + + /** + * The index of the document this chunk belongs to + */ + index?: number; + + /** + * The object type + */ + object?: string; +} + +/** + * A single embedding result + */ +export interface EmbeddingObject { + /** + * Base64-encoded embedding vector. For base64_int8: decode to signed int8 array + * (length = dimensions). For base64_binary: decode to packed bits (length = + * dimensions / 8 bytes). + */ + embedding?: string; + + /** + * The index of the input text this embedding corresponds to + */ + index?: number; + + /** + * The object type + */ + object?: string; +} + +/** + * Token usage for the embeddings request + */ +export interface EmbeddingsUsage { + /** + * Cost breakdown for the request + */ + cost?: EmbeddingsUsage.Cost; + + /** + * Number of tokens in the input texts + */ + prompt_tokens?: number; + + /** + * Total number of tokens processed + */ + total_tokens?: number; +} + +export namespace EmbeddingsUsage { + /** + * Cost breakdown for the request + */ + export interface Cost { + /** + * Currency of the cost values + */ + currency?: 'USD'; + + /** + * Cost for input tokens in USD + */ + input_cost?: number; + + /** + * Total cost for the request in USD + */ + total_cost?: number; + } +} + /** * Defines a JSON schema for structured output validation */ diff --git a/src/version.ts b/src/version.ts index 4e76ac1..7434729 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.23.2'; // x-release-please-version +export const VERSION = '0.24.0'; // x-release-please-version diff --git a/tests/api-resources/contextualized-embeddings.test.ts b/tests/api-resources/contextualized-embeddings.test.ts new file mode 100644 index 0000000..a346ef5 --- /dev/null +++ b/tests/api-resources/contextualized-embeddings.test.ts @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource contextualizedEmbeddings', () => { + // Prism tests are disabled + test.skip('create: only required params', async () => { + const responsePromise = client.contextualizedEmbeddings.create({ + input: [['x']], + model: 'pplx-embed-context-v1-0.6b', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('create: required and optional params', async () => { + const response = await client.contextualizedEmbeddings.create({ + input: [['x']], + model: 'pplx-embed-context-v1-0.6b', + dimensions: 128, + encoding_format: 'base64_int8', + }); + }); +}); diff --git a/tests/api-resources/embeddings.test.ts b/tests/api-resources/embeddings.test.ts new file mode 100644 index 0000000..6536898 --- /dev/null +++ b/tests/api-resources/embeddings.test.ts @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource embeddings', () => { + // Prism tests are disabled + test.skip('create: only required params', async () => { + const responsePromise = client.embeddings.create({ input: 'x', model: 'pplx-embed-v1-0.6b' }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('create: required and optional params', async () => { + const response = await client.embeddings.create({ + input: 'x', + model: 'pplx-embed-v1-0.6b', + dimensions: 128, + encoding_format: 'base64_int8', + }); + }); +});