@perplexity-ai/perplexity_ai 0.42.0 → 0.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.43.1](https://github.com/perplexityai/perplexity-node/compare/v0.43.0...v0.43.1) (2026-11-19)
4
+
5
+
6
+ ### Documentation
7
+
8
+ * **embeddings:** recommend pplx-embed-v2 models and add v2 tests ([#126](https://github.com/perplexityai/perplexity-node/issues/126)) ([d45ed77](https://github.com/perplexityai/perplexity-node/commit/d45ed7775667f9ef76d75598c2b17669f9784b91))
9
+
10
+ ## [0.43.0](https://github.com/perplexityai/perplexity-node/compare/v0.42.0...v0.43.0) (2026-11-18)
11
+
12
+
13
+ ### Features
14
+
15
+ * **api:** add context resource ([aa66ec6](https://github.com/perplexityai/perplexity-node/commit/aa66ec6cc8b473d3b73b4ff1889c632c00b10e4d))
16
+
3
17
  ## [0.42.0](https://github.com/perplexityai/perplexity-node/compare/v0.41.0...v0.42.0) (2026-11-17)
4
18
 
5
19
 
package/README.md CHANGED
@@ -57,6 +57,63 @@ const streamChunk = await client.chat.completions.create({
57
57
  console.log(streamChunk.choices[0].message.content);
58
58
  ```
59
59
 
60
+ ### Embeddings
61
+
62
+ Use the pplx-embed-v2 models. Start with `pplx-embed-v2-context-0.6b` for higher
63
+ throughput and lower latency, and choose `pplx-embed-v2-context-9b` for retrieval
64
+ quality. Their 1024-dimension outputs share one embedding space, so you can index
65
+ with one model and query with the other. The `pplx-embed-v1-*` and
66
+ `pplx-embed-context-v1-*` models still work but will be phased out during 2027.
67
+ See the [Embeddings guide](https://docs.perplexity.ai/docs/embeddings/contextualized-embeddings)
68
+ for parameters and limits.
69
+
70
+ v2 models require `input_type`: `'query'` for the text a user types to search, and
71
+ `'document'` for everything you index, including short titles or summaries. The
72
+ shape of `input` sets the shape of the response:
73
+
74
+ | `input` | `input_type` | Response |
75
+ | -------------------------------------------- | ------------ | ----------------------------------------------------------- |
76
+ | String or array of strings | `'query'` | One embedding per query, `data[i].embedding` |
77
+ | String or array of strings | `'document'` | One embedding per document, `data[i].embedding` |
78
+ | Array of chunk arrays, one per document | `'document'` | One embedding per chunk, `data[i].data[j].embedding` |
79
+ | Array of image objects | `'document'` | One embedding per image, `data[i].embedding` |
80
+ | Array of image objects with `num_chunks` > 1 | `'document'` | One embedding per image region, `data[i].data[j].embedding` |
81
+
82
+ ```js
83
+ import Perplexity from '@perplexity-ai/perplexity_ai';
84
+
85
+ const client = new Perplexity();
86
+
87
+ const query = await client.embeddings.create({
88
+ input: ['What drives scientific breakthroughs?'],
89
+ input_type: 'query',
90
+ model: 'pplx-embed-v2-context-0.6b',
91
+ });
92
+ console.log(query.data?.[0]?.embedding);
93
+
94
+ // Each chunk is embedded in the context of its whole document. Send
95
+ // non-overlapping chunks in source order.
96
+ const documents = await client.embeddings.create({
97
+ input: [
98
+ ['Curiosity sparks questions.', 'They drive breakthroughs.'],
99
+ ['The Curiosity rover explores Mars.'],
100
+ ],
101
+ input_type: 'document',
102
+ model: 'pplx-embed-v2-context-0.6b',
103
+ });
104
+ for (const document of documents.data ?? []) {
105
+ for (const chunk of document.data ?? []) {
106
+ console.log(document.index, chunk.index, chunk.embedding);
107
+ }
108
+ }
109
+ ```
110
+
111
+ Images are base64 data URIs such as
112
+ `{ type: 'image', image: 'data:image/png;base64,...' }`. A request holds either
113
+ text or images, not both. Embeddings are base64-encoded signed int8 values by
114
+ default; decode one with `new Int8Array(Buffer.from(embedding, 'base64'))` and
115
+ compare with cosine similarity.
116
+
60
117
  ### Advanced Search Features
61
118
 
62
119
  #### Multi-Query Search
@@ -558,6 +558,104 @@ export type ContentPartOutput = {
558
558
  };
559
559
  export type ContentPartTypeInput = "output_text";
560
560
  export type ContentPartTypeOutput = "output_text";
561
+ export type ContextCostInput = {
562
+ currency: ContextCurrencyInput;
563
+ total_cost: number;
564
+ };
565
+ export type ContextCostOutput = {
566
+ currency: ContextCurrencyOutput;
567
+ total_cost: number;
568
+ };
569
+ export type ContextCurrencyInput = "USD";
570
+ export type ContextCurrencyOutput = "USD";
571
+ export type ContextDocumentInput = {
572
+ highlights?: string;
573
+ html?: string;
574
+ links?: string[];
575
+ markdown?: string;
576
+ metadata?: ContextMetadataInput;
577
+ status: ContextStatusInput;
578
+ url: string;
579
+ };
580
+ export type ContextDocumentOutput = {
581
+ highlights?: string;
582
+ html?: string;
583
+ links?: string[];
584
+ markdown?: string;
585
+ metadata?: ContextMetadataOutput;
586
+ status: ContextStatusOutput;
587
+ url: string;
588
+ };
589
+ export type ContextHighlightsInput = {
590
+ max_tokens_per_url?: number;
591
+ query: string;
592
+ };
593
+ export type ContextHighlightsOutput = {
594
+ max_tokens_per_url?: number;
595
+ query: string;
596
+ };
597
+ export type ContextMetadataInput = {
598
+ author?: string;
599
+ content_type?: string;
600
+ description?: string;
601
+ fetched_at?: string;
602
+ language?: string;
603
+ last_modified?: string;
604
+ origin?: "cached" | "live";
605
+ published_date?: string;
606
+ source_url: string;
607
+ title?: string;
608
+ } & Record<string, (string | string[]) | string | string | string | string | string | string | ("cached" | "live") | string | string | string>;
609
+ export type ContextMetadataOutput = {
610
+ author?: string;
611
+ content_type?: string;
612
+ description?: string;
613
+ fetched_at?: string;
614
+ language?: string;
615
+ last_modified?: string;
616
+ origin?: "cached" | "live";
617
+ published_date?: string;
618
+ source_url: string;
619
+ title?: string;
620
+ } & Record<string, (string | string[]) | string | string | string | string | string | string | ("cached" | "live") | string | string | string>;
621
+ export type ContextRequestInput = {
622
+ cache_only?: boolean;
623
+ formats?: ("markdown" | "html" | "links" | "highlights")[];
624
+ highlights?: ContextHighlightsInput;
625
+ if_modified_since?: string;
626
+ max_age_seconds?: number;
627
+ timeout_ms?: number;
628
+ urls: string[];
629
+ };
630
+ export type ContextRequestOutput = {
631
+ cache_only?: boolean;
632
+ formats?: ("markdown" | "html" | "links" | "highlights")[];
633
+ highlights?: ContextHighlightsOutput;
634
+ if_modified_since?: string;
635
+ max_age_seconds?: number;
636
+ timeout_ms?: number;
637
+ urls: string[];
638
+ };
639
+ export type ContextResponseInput = {
640
+ request_id: string;
641
+ results: ContextDocumentInput[];
642
+ usage: ContextUsageInput;
643
+ };
644
+ export type ContextResponseOutput = {
645
+ request_id: string;
646
+ results: ContextDocumentOutput[];
647
+ usage: ContextUsageOutput;
648
+ };
649
+ export type ContextStatusInput = {
650
+ message?: string;
651
+ status_code?: number;
652
+ type: "ok" | "not_modified" | "invalid_url" | "blocked" | "bot_challenge" | "crawl_failed" | "crawl_timeout" | "no_text" | "no_content" | "internal_error";
653
+ };
654
+ export type ContextStatusOutput = {
655
+ message?: string;
656
+ status_code?: number;
657
+ type: "ok" | "not_modified" | "invalid_url" | "blocked" | "bot_challenge" | "crawl_failed" | "crawl_timeout" | "no_text" | "no_content" | "internal_error";
658
+ };
561
659
  export type ContextualizedEmbeddingObjectInput = {
562
660
  data?: EmbeddingObjectInput[];
563
661
  index?: number;
@@ -592,6 +690,14 @@ export type ContextualizedEmbeddingsResponseOutput = {
592
690
  object?: string;
593
691
  usage?: EmbeddingsUsageOutput;
594
692
  };
693
+ export type ContextUsageInput = {
694
+ cost: ContextCostInput;
695
+ fetched_urls: number;
696
+ };
697
+ export type ContextUsageOutput = {
698
+ cost: ContextCostOutput;
699
+ fetched_urls: number;
700
+ };
595
701
  export type CostInput = {
596
702
  citation_tokens_cost?: number | null;
597
703
  input_tokens_cost: number;
@@ -2242,6 +2348,7 @@ export type ResponsesObjectTypeInput = "response";
2242
2348
  export type ResponsesObjectTypeOutput = "response";
2243
2349
  export type ResponsesRequestInput = {
2244
2350
  background?: boolean | null;
2351
+ code_mode?: boolean;
2245
2352
  effort?: string;
2246
2353
  input: InputInput;
2247
2354
  instructions?: string;
@@ -2269,6 +2376,7 @@ export type ResponsesRequestInput = {
2269
2376
  };
2270
2377
  export type ResponsesRequestOutput = {
2271
2378
  background?: boolean | null;
2379
+ code_mode?: boolean;
2272
2380
  effort?: string;
2273
2381
  input: InputOutput;
2274
2382
  instructions?: string;
@@ -2983,6 +3091,11 @@ export declare class ChatResource {
2983
3091
  readonly completions: ChatCompletionsResource;
2984
3092
  constructor(client: SdkTransport);
2985
3093
  }
3094
+ export declare class ContextResource {
3095
+ private readonly _client;
3096
+ constructor(client: SdkTransport);
3097
+ create(body: ContextRequestInput, options?: RequestOptions): APIPromise<ContextResponseOutput>;
3098
+ }
2986
3099
  export declare class ContextualizedEmbeddingsResource {
2987
3100
  private readonly _client;
2988
3101
  constructor(client: SdkTransport);
@@ -3126,6 +3239,7 @@ export declare class PerplexitySdk {
3126
3239
  readonly batches: BatchesResource;
3127
3240
  readonly browser: BrowserResource;
3128
3241
  readonly chat: ChatResource;
3242
+ readonly context: ContextResource;
3129
3243
  readonly contextualizedEmbeddings: ContextualizedEmbeddingsResource;
3130
3244
  readonly decisions: DecisionsResource;
3131
3245
  readonly embeddings: EmbeddingsResource;
@@ -3145,6 +3259,8 @@ export declare class Browser extends BrowserResource {
3145
3259
  }
3146
3260
  export declare class Chat extends ChatResource {
3147
3261
  }
3262
+ export declare class Context extends ContextResource {
3263
+ }
3148
3264
  export declare class ContextualizedEmbeddings extends ContextualizedEmbeddingsResource {
3149
3265
  }
3150
3266
  export declare class Decisions extends DecisionsResource {
@@ -3173,6 +3289,11 @@ export type ChatMessageInput = ChatMessageInputInput;
3173
3289
  export type ChatMessageOutput = ChatMessageOutputOutput;
3174
3290
  export type Choice = ChoiceOutput;
3175
3291
  export type ContentPart = ContentPartOutput;
3292
+ export type ContextCreateParams = ContextRequestInput;
3293
+ export type ContextCreateResponse = Awaited<ReturnType<ContextResource["create"]>>;
3294
+ export type ContextDocument = ContextDocumentOutput;
3295
+ export type ContextMetadata = ContextMetadataOutput;
3296
+ export type ContextStatus = ContextStatusOutput;
3176
3297
  export type ContextualizedEmbeddingCreateParams = ContextualizedEmbeddingsRequestInput;
3177
3298
  export type ContextualizedEmbeddingCreateResponse = ContextualizedEmbeddingsResponseOutput;
3178
3299
  export type ContextualizedEmbeddingObject = ContextualizedEmbeddingObjectOutput;
@@ -3293,6 +3414,13 @@ export declare namespace Chat {
3293
3414
  };
3294
3415
  }
3295
3416
  }
3417
+ export declare namespace Context {
3418
+ type ContextCreateParams = ContextRequestInput;
3419
+ type ContextCreateResponse = Awaited<ReturnType<ContextResource["create"]>>;
3420
+ type ContextDocument = ContextDocumentOutput;
3421
+ type ContextMetadata = ContextMetadataOutput;
3422
+ type ContextStatus = ContextStatusOutput;
3423
+ }
3296
3424
  export declare namespace ContextualizedEmbeddings {
3297
3425
  type ContextualizedEmbeddingCreateParams = ContextualizedEmbeddingsRequestInput;
3298
3426
  type ContextualizedEmbeddingCreateResponse = ContextualizedEmbeddingsResponseOutput;