@personize/sdk 0.6.6 → 0.7.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/dist/client.d.ts +31 -1
- package/dist/client.js +96 -0
- package/dist/types.d.ts +356 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PersonizeConfig, ApiResponse, MeResponse, TestResponse, ListOptions, GuidelinesResponse, GuidelineSectionOptions, GuidelineUpdatePayload, GuidelineCreatePayload, GuidelineHistoryResponse, GuidelineHistoryOptions, CollectionsResponse, CollectionCreatePayload, CollectionUpdatePayload, CollectionHistoryOptions, CollectionHistoryResponse, SmartGuidelinesOptions, SmartGuidelinesResponse, PromptOptions, PromptResponse, PromptStreamOptions, PromptSSEEvent, AgentRunOptions, AgentResponse, MemorizeOptions, SmartRecallOptions, RecallOptions, RecallResponse, SearchOptions, SearchResponse, BatchMemorizeOptions, SmartDigestOptions, SmartDigestResponse, EvaluateMemorizationOptions, EvaluateMemorizationResponse, UpdatePropertyOptions, UpdateResult, BulkUpdateOptions, BulkUpdateResult, PropertyHistoryOptions, PropertyHistoryResult, QueryPropertiesOptions, QueryPropertiesResult, DeleteMemoriesOptions, DeleteRecordOptions, DeletionResult, CancelDeletionOptions, CancelDeletionResult, FilterByPropertyOptions, FilterByPropertyResult, GetPropertiesOptions, GetPropertiesResponse } from './types';
|
|
1
|
+
import { PersonizeConfig, ApiResponse, MeResponse, TestResponse, ListOptions, GuidelinesResponse, GuidelineSectionOptions, GuidelineUpdatePayload, GuidelineCreatePayload, GuidelineHistoryResponse, GuidelineHistoryOptions, CollectionsResponse, CollectionCreatePayload, CollectionUpdatePayload, CollectionHistoryOptions, CollectionHistoryResponse, SmartGuidelinesOptions, SmartGuidelinesResponse, PromptOptions, PromptResponse, PromptStreamOptions, PromptSSEEvent, AgentRunOptions, AgentResponse, MemorizeOptions, SmartRecallOptions, RecallOptions, RecallResponse, SearchOptions, SearchResponse, BatchMemorizeOptions, SmartDigestOptions, SmartDigestResponse, EvaluateMemorizationOptions, EvaluateMemorizationResponse, UpdatePropertyOptions, UpdateResult, BulkUpdateOptions, BulkUpdateResult, PropertyHistoryOptions, PropertyHistoryResult, QueryPropertiesOptions, QueryPropertiesResult, DeleteMemoriesOptions, DeleteRecordOptions, DeletionResult, CancelDeletionOptions, CancelDeletionResult, FilterByPropertyOptions, FilterByPropertyResult, GetPropertiesOptions, GetPropertiesResponse, ResponsesCreateOptions, ResponsesCompletedResult, ChatCompletionsOptions, ChatCompletionResult, SimilarOptions, SimilarResponse, SegmentOptions, SegmentResponse } from './types';
|
|
2
2
|
export declare class Personize {
|
|
3
3
|
private client;
|
|
4
4
|
private _organizationId?;
|
|
@@ -229,6 +229,18 @@ export declare class Personize {
|
|
|
229
229
|
* POST /api/v1/properties — Get record properties with schema descriptions.
|
|
230
230
|
*/
|
|
231
231
|
properties: (data: GetPropertiesOptions) => Promise<ApiResponse<GetPropertiesResponse>>;
|
|
232
|
+
/**
|
|
233
|
+
* POST /api/v1/similar -- Find records similar to a seed record.
|
|
234
|
+
* Returns ranked results with similarity tiers.
|
|
235
|
+
* @see https://docs.personize.ai/api#similar
|
|
236
|
+
*/
|
|
237
|
+
similar: (data: SimilarOptions) => Promise<ApiResponse<SimilarResponse>>;
|
|
238
|
+
/**
|
|
239
|
+
* POST /api/v1/segment -- Bucket all records into similarity tiers.
|
|
240
|
+
* Supports record-based or text-based seeds.
|
|
241
|
+
* @see https://docs.personize.ai/api#segment
|
|
242
|
+
*/
|
|
243
|
+
segment: (data: SegmentOptions) => Promise<ApiResponse<SegmentResponse>>;
|
|
232
244
|
};
|
|
233
245
|
evaluate: {
|
|
234
246
|
/**
|
|
@@ -237,4 +249,22 @@ export declare class Personize {
|
|
|
237
249
|
*/
|
|
238
250
|
memorizationAccuracy: (data: EvaluateMemorizationOptions) => Promise<ApiResponse<EvaluateMemorizationResponse>>;
|
|
239
251
|
};
|
|
252
|
+
responses: {
|
|
253
|
+
/**
|
|
254
|
+
* POST /api/v1/responses — Execute step-driven orchestration.
|
|
255
|
+
*
|
|
256
|
+
* If tools with execute functions are provided (Record format), the SDK
|
|
257
|
+
* automatically handles the tool execution loop: execute locally, send
|
|
258
|
+
* results back, repeat until completed.
|
|
259
|
+
*/
|
|
260
|
+
create: (options: ResponsesCreateOptions) => Promise<ResponsesCompletedResult>;
|
|
261
|
+
};
|
|
262
|
+
chat: {
|
|
263
|
+
completions: {
|
|
264
|
+
/**
|
|
265
|
+
* POST /api/v1/chat/completions — OpenAI-compatible chat completion.
|
|
266
|
+
*/
|
|
267
|
+
create: (options: ChatCompletionsOptions) => Promise<ChatCompletionResult>;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
240
270
|
}
|
package/dist/client.js
CHANGED
|
@@ -456,6 +456,24 @@ class Personize {
|
|
|
456
456
|
});
|
|
457
457
|
return response.data;
|
|
458
458
|
},
|
|
459
|
+
/**
|
|
460
|
+
* POST /api/v1/similar -- Find records similar to a seed record.
|
|
461
|
+
* Returns ranked results with similarity tiers.
|
|
462
|
+
* @see https://docs.personize.ai/api#similar
|
|
463
|
+
*/
|
|
464
|
+
similar: async (data) => {
|
|
465
|
+
const response = await this.client.post('/api/v1/similar', data);
|
|
466
|
+
return response.data;
|
|
467
|
+
},
|
|
468
|
+
/**
|
|
469
|
+
* POST /api/v1/segment -- Bucket all records into similarity tiers.
|
|
470
|
+
* Supports record-based or text-based seeds.
|
|
471
|
+
* @see https://docs.personize.ai/api#segment
|
|
472
|
+
*/
|
|
473
|
+
segment: async (data) => {
|
|
474
|
+
const response = await this.client.post('/api/v1/segment', data);
|
|
475
|
+
return response.data;
|
|
476
|
+
},
|
|
459
477
|
};
|
|
460
478
|
this.evaluate = {
|
|
461
479
|
/**
|
|
@@ -467,6 +485,84 @@ class Personize {
|
|
|
467
485
|
return response.data;
|
|
468
486
|
},
|
|
469
487
|
};
|
|
488
|
+
this.responses = {
|
|
489
|
+
/**
|
|
490
|
+
* POST /api/v1/responses — Execute step-driven orchestration.
|
|
491
|
+
*
|
|
492
|
+
* If tools with execute functions are provided (Record format), the SDK
|
|
493
|
+
* automatically handles the tool execution loop: execute locally, send
|
|
494
|
+
* results back, repeat until completed.
|
|
495
|
+
*/
|
|
496
|
+
create: async (options) => {
|
|
497
|
+
// Extract execute functions from tools (they don't get sent to server)
|
|
498
|
+
let toolSchemas;
|
|
499
|
+
let executeMap;
|
|
500
|
+
if (options.tools && !Array.isArray(options.tools)) {
|
|
501
|
+
// Record format — extract execute functions
|
|
502
|
+
executeMap = new Map();
|
|
503
|
+
toolSchemas = [];
|
|
504
|
+
for (const [name, def] of Object.entries(options.tools)) {
|
|
505
|
+
executeMap.set(name, def.execute);
|
|
506
|
+
toolSchemas.push({
|
|
507
|
+
type: 'function',
|
|
508
|
+
function: { name, description: def.description, parameters: def.parameters },
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
else if (Array.isArray(options.tools)) {
|
|
513
|
+
toolSchemas = options.tools;
|
|
514
|
+
}
|
|
515
|
+
// Build request body (exclude execute functions)
|
|
516
|
+
const body = { ...options, tools: toolSchemas };
|
|
517
|
+
// Tool execution loop
|
|
518
|
+
let maxRounds = 20;
|
|
519
|
+
while (maxRounds-- > 0) {
|
|
520
|
+
const response = await this.client.post('/api/v1/responses', body);
|
|
521
|
+
const result = response.data;
|
|
522
|
+
if (result.status === 'completed') {
|
|
523
|
+
return result;
|
|
524
|
+
}
|
|
525
|
+
// requires_action — execute tools locally
|
|
526
|
+
if (!executeMap || executeMap.size === 0) {
|
|
527
|
+
// No execute functions provided — return as-is (caller handles manually)
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
const toolResults = [];
|
|
531
|
+
for (const tc of result.required_action.tool_calls) {
|
|
532
|
+
const executeFn = executeMap.get(tc.name);
|
|
533
|
+
if (!executeFn) {
|
|
534
|
+
toolResults.push({ tool_call_id: tc.id, output: JSON.stringify({ error: `No execute function for tool: ${tc.name}` }) });
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
try {
|
|
538
|
+
const output = await executeFn(tc.args);
|
|
539
|
+
toolResults.push({ tool_call_id: tc.id, output: typeof output === 'string' ? output : JSON.stringify(output) });
|
|
540
|
+
}
|
|
541
|
+
catch (err) {
|
|
542
|
+
toolResults.push({ tool_call_id: tc.id, output: JSON.stringify({ error: err.message }) });
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
// Send continuation request
|
|
546
|
+
body.conversation = result.conversation;
|
|
547
|
+
body.conversation_signature = result.conversation_signature;
|
|
548
|
+
body.remaining_steps = result.remaining_steps;
|
|
549
|
+
body.completed_step_count = result.completed_step_count;
|
|
550
|
+
body.tool_results = toolResults;
|
|
551
|
+
}
|
|
552
|
+
throw new Error('Tool execution loop exceeded maximum rounds (20)');
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
this.chat = {
|
|
556
|
+
completions: {
|
|
557
|
+
/**
|
|
558
|
+
* POST /api/v1/chat/completions — OpenAI-compatible chat completion.
|
|
559
|
+
*/
|
|
560
|
+
create: async (options) => {
|
|
561
|
+
const response = await this.client.post('/api/v1/chat/completions', options);
|
|
562
|
+
return response.data;
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
};
|
|
470
566
|
this.maxRetries = config.maxRetries ?? 3;
|
|
471
567
|
this.retryDelay = config.retryDelay ?? 1000;
|
|
472
568
|
this.client = axios_1.default.create({
|
package/dist/types.d.ts
CHANGED
|
@@ -760,6 +760,10 @@ export interface SmartRecallOptions {
|
|
|
760
760
|
recency_half_life_days?: number;
|
|
761
761
|
/** Metadata filters for narrowing results. */
|
|
762
762
|
filters?: Record<string, unknown>;
|
|
763
|
+
/** Group results by record. Returns recordGroups array alongside flat results. */
|
|
764
|
+
groupByRecord?: boolean;
|
|
765
|
+
/** Alias for groupByRecord. */
|
|
766
|
+
group_by_record?: boolean;
|
|
763
767
|
}
|
|
764
768
|
/** @deprecated Use SmartRecallOptions instead. */
|
|
765
769
|
export type RecallProOptions = SmartRecallOptions;
|
|
@@ -802,6 +806,10 @@ export interface RecallOptions {
|
|
|
802
806
|
collectionName?: string;
|
|
803
807
|
/** Compatibility alias for collection scoping by name. */
|
|
804
808
|
collectionNames?: string[];
|
|
809
|
+
/** Group results by record. Returns recordGroups array alongside flat results. */
|
|
810
|
+
groupByRecord?: boolean;
|
|
811
|
+
/** Alias for groupByRecord. */
|
|
812
|
+
group_by_record?: boolean;
|
|
805
813
|
}
|
|
806
814
|
export interface RecallResultItem {
|
|
807
815
|
content?: string;
|
|
@@ -1371,3 +1379,351 @@ export interface EvaluateMemorizationResponse {
|
|
|
1371
1379
|
propertiesAttempted: number;
|
|
1372
1380
|
};
|
|
1373
1381
|
}
|
|
1382
|
+
export interface StepDefinition {
|
|
1383
|
+
prompt: string;
|
|
1384
|
+
order?: number;
|
|
1385
|
+
tools?: string[];
|
|
1386
|
+
max_steps?: number;
|
|
1387
|
+
}
|
|
1388
|
+
export interface PersonizeExtensions {
|
|
1389
|
+
governance?: {
|
|
1390
|
+
guideline_ids?: string[];
|
|
1391
|
+
mode?: 'fast' | 'deep';
|
|
1392
|
+
};
|
|
1393
|
+
memory?: {
|
|
1394
|
+
record_id?: string;
|
|
1395
|
+
recall?: boolean;
|
|
1396
|
+
};
|
|
1397
|
+
mcp_integration_ids?: string[];
|
|
1398
|
+
outputs?: Array<{
|
|
1399
|
+
key: string;
|
|
1400
|
+
type: string;
|
|
1401
|
+
}>;
|
|
1402
|
+
memorize?: {
|
|
1403
|
+
record_id?: string;
|
|
1404
|
+
collection?: string;
|
|
1405
|
+
capture_tool_results?: boolean;
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
export interface ClientToolDefinition {
|
|
1409
|
+
type: 'function';
|
|
1410
|
+
function: {
|
|
1411
|
+
name: string;
|
|
1412
|
+
description: string;
|
|
1413
|
+
parameters: Record<string, unknown>;
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
export interface ResponsesCreateOptions {
|
|
1417
|
+
steps?: StepDefinition[];
|
|
1418
|
+
messages?: Array<{
|
|
1419
|
+
role: string;
|
|
1420
|
+
content: string;
|
|
1421
|
+
}>;
|
|
1422
|
+
tools?: ClientToolDefinition[] | Record<string, {
|
|
1423
|
+
description: string;
|
|
1424
|
+
parameters: Record<string, unknown>;
|
|
1425
|
+
execute: (args: any) => Promise<any>;
|
|
1426
|
+
}>;
|
|
1427
|
+
model?: string;
|
|
1428
|
+
provider?: string;
|
|
1429
|
+
tier?: string;
|
|
1430
|
+
temperature?: number;
|
|
1431
|
+
max_tokens?: number;
|
|
1432
|
+
system_prompt?: string;
|
|
1433
|
+
session_id?: string;
|
|
1434
|
+
llm_api_key?: string;
|
|
1435
|
+
openrouter_api_key?: string;
|
|
1436
|
+
personize?: PersonizeExtensions;
|
|
1437
|
+
attachments?: Array<{
|
|
1438
|
+
name: string;
|
|
1439
|
+
mimeType: string;
|
|
1440
|
+
url?: string;
|
|
1441
|
+
content?: string;
|
|
1442
|
+
}>;
|
|
1443
|
+
conversation?: any[];
|
|
1444
|
+
conversation_signature?: string;
|
|
1445
|
+
remaining_steps?: StepDefinition[];
|
|
1446
|
+
completed_step_count?: number;
|
|
1447
|
+
}
|
|
1448
|
+
export interface ResponsesToolCall {
|
|
1449
|
+
id: string;
|
|
1450
|
+
name: string;
|
|
1451
|
+
args: Record<string, unknown>;
|
|
1452
|
+
}
|
|
1453
|
+
export interface ResponsesStepResult {
|
|
1454
|
+
order: number;
|
|
1455
|
+
text: string;
|
|
1456
|
+
tool_calls: Array<{
|
|
1457
|
+
name: string;
|
|
1458
|
+
args: Record<string, unknown>;
|
|
1459
|
+
result?: unknown;
|
|
1460
|
+
}>;
|
|
1461
|
+
usage: {
|
|
1462
|
+
prompt_tokens: number;
|
|
1463
|
+
completion_tokens: number;
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
export interface ResponsesCompletedResult {
|
|
1467
|
+
id: string;
|
|
1468
|
+
status: 'completed';
|
|
1469
|
+
session_id: string;
|
|
1470
|
+
output: Array<{
|
|
1471
|
+
type: string;
|
|
1472
|
+
role: string;
|
|
1473
|
+
content: Array<{
|
|
1474
|
+
type: string;
|
|
1475
|
+
text: string;
|
|
1476
|
+
}>;
|
|
1477
|
+
}>;
|
|
1478
|
+
steps: ResponsesStepResult[];
|
|
1479
|
+
outputs?: Record<string, unknown>;
|
|
1480
|
+
usage: {
|
|
1481
|
+
prompt_tokens: number;
|
|
1482
|
+
completion_tokens: number;
|
|
1483
|
+
total_tokens: number;
|
|
1484
|
+
};
|
|
1485
|
+
metadata: {
|
|
1486
|
+
tier: string;
|
|
1487
|
+
credits_charged: number;
|
|
1488
|
+
byok?: boolean;
|
|
1489
|
+
model?: string;
|
|
1490
|
+
provider?: string;
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
export interface ResponsesRequiresActionResult {
|
|
1494
|
+
id: string;
|
|
1495
|
+
status: 'requires_action';
|
|
1496
|
+
session_id: string;
|
|
1497
|
+
required_action: {
|
|
1498
|
+
type: 'tool_calls';
|
|
1499
|
+
tool_calls: ResponsesToolCall[];
|
|
1500
|
+
};
|
|
1501
|
+
conversation: any[];
|
|
1502
|
+
remaining_steps: StepDefinition[];
|
|
1503
|
+
completed_step_count: number;
|
|
1504
|
+
conversation_signature: string;
|
|
1505
|
+
usage: {
|
|
1506
|
+
prompt_tokens: number;
|
|
1507
|
+
completion_tokens: number;
|
|
1508
|
+
total_tokens: number;
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
export type ResponsesResult = ResponsesCompletedResult | ResponsesRequiresActionResult;
|
|
1512
|
+
export interface ChatCompletionsOptions {
|
|
1513
|
+
model?: string;
|
|
1514
|
+
provider?: string;
|
|
1515
|
+
tier?: string;
|
|
1516
|
+
messages: Array<{
|
|
1517
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
1518
|
+
content: string | null;
|
|
1519
|
+
tool_call_id?: string;
|
|
1520
|
+
tool_calls?: any[];
|
|
1521
|
+
}>;
|
|
1522
|
+
tools?: ClientToolDefinition[];
|
|
1523
|
+
tool_choice?: 'auto' | 'none' | 'required';
|
|
1524
|
+
temperature?: number;
|
|
1525
|
+
max_tokens?: number;
|
|
1526
|
+
llm_api_key?: string;
|
|
1527
|
+
openrouter_api_key?: string;
|
|
1528
|
+
personize?: PersonizeExtensions;
|
|
1529
|
+
}
|
|
1530
|
+
export interface ChatCompletionChoice {
|
|
1531
|
+
index: number;
|
|
1532
|
+
message: {
|
|
1533
|
+
role: 'assistant';
|
|
1534
|
+
content: string | null;
|
|
1535
|
+
tool_calls?: Array<{
|
|
1536
|
+
id: string;
|
|
1537
|
+
type: 'function';
|
|
1538
|
+
function: {
|
|
1539
|
+
name: string;
|
|
1540
|
+
arguments: string;
|
|
1541
|
+
};
|
|
1542
|
+
}>;
|
|
1543
|
+
};
|
|
1544
|
+
finish_reason: 'stop' | 'tool_calls' | 'length';
|
|
1545
|
+
}
|
|
1546
|
+
export interface ChatCompletionResult {
|
|
1547
|
+
id: string;
|
|
1548
|
+
object: 'chat.completion';
|
|
1549
|
+
created: number;
|
|
1550
|
+
model: string;
|
|
1551
|
+
choices: ChatCompletionChoice[];
|
|
1552
|
+
usage: {
|
|
1553
|
+
prompt_tokens: number;
|
|
1554
|
+
completion_tokens: number;
|
|
1555
|
+
total_tokens: number;
|
|
1556
|
+
};
|
|
1557
|
+
session_id?: string;
|
|
1558
|
+
metadata?: {
|
|
1559
|
+
tier: string;
|
|
1560
|
+
credits_charged: number;
|
|
1561
|
+
byok?: boolean;
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
/** Options for POST /api/v1/similar -- find records similar to a seed record. */
|
|
1565
|
+
export interface SimilarOptions {
|
|
1566
|
+
/** Seed record identifier. Provide exactly one: recordId, email, websiteUrl, or customKey. */
|
|
1567
|
+
seed: {
|
|
1568
|
+
recordId?: string;
|
|
1569
|
+
email?: string;
|
|
1570
|
+
websiteUrl?: string;
|
|
1571
|
+
customKeyName?: string;
|
|
1572
|
+
customKeyValue?: string;
|
|
1573
|
+
};
|
|
1574
|
+
/** Seed entity type. Inferred from seed key if omitted (email -> contact, websiteUrl -> company). */
|
|
1575
|
+
type?: string;
|
|
1576
|
+
/** What dimensions drive similarity. Default: 'hybrid'. */
|
|
1577
|
+
dimensions?: 'properties' | 'memories' | 'hybrid' | 'connections';
|
|
1578
|
+
/** Fine-tune which properties/connections matter. */
|
|
1579
|
+
dimensionFilters?: {
|
|
1580
|
+
propertyNames?: string[];
|
|
1581
|
+
collectionIds?: string[];
|
|
1582
|
+
systemNames?: string[];
|
|
1583
|
+
keywords?: string[];
|
|
1584
|
+
entities?: string[];
|
|
1585
|
+
};
|
|
1586
|
+
/** Scoring mode. Default: 'balanced'. */
|
|
1587
|
+
rankingMode?: 'balanced' | 'weighted';
|
|
1588
|
+
/** Dimension weights. Only used with rankingMode: 'weighted'. */
|
|
1589
|
+
weights?: {
|
|
1590
|
+
properties?: number;
|
|
1591
|
+
memories?: number;
|
|
1592
|
+
};
|
|
1593
|
+
/** Scope search to specific candidates. */
|
|
1594
|
+
candidatePool?: {
|
|
1595
|
+
recordIds?: string[];
|
|
1596
|
+
type?: string;
|
|
1597
|
+
collectionIds?: string[];
|
|
1598
|
+
};
|
|
1599
|
+
/** Max results per page (default: 25, max: 500). */
|
|
1600
|
+
topK?: number;
|
|
1601
|
+
/** Pagination offset (default: 0). */
|
|
1602
|
+
offset?: number;
|
|
1603
|
+
/** Min similarity threshold (default: 0.3). */
|
|
1604
|
+
minScore?: number;
|
|
1605
|
+
/** Include tier arrays in response (default: true). */
|
|
1606
|
+
includeTiers?: boolean;
|
|
1607
|
+
/** Override tier thresholds. */
|
|
1608
|
+
tierThresholds?: {
|
|
1609
|
+
very_similar?: number;
|
|
1610
|
+
similar?: number;
|
|
1611
|
+
};
|
|
1612
|
+
/** Max matched snippets per result (default: 3, max: 5). */
|
|
1613
|
+
maxSnippetsPerResult?: number;
|
|
1614
|
+
/** Batch mode: return flat list of all matching recordIds (default: false). */
|
|
1615
|
+
returnAllIds?: boolean;
|
|
1616
|
+
}
|
|
1617
|
+
export interface SimilarResult {
|
|
1618
|
+
recordId: string;
|
|
1619
|
+
type: string;
|
|
1620
|
+
score: number;
|
|
1621
|
+
tier: 'very_similar' | 'similar' | 'somewhat_similar';
|
|
1622
|
+
matchBreakdown: {
|
|
1623
|
+
propertiesScore: number | null;
|
|
1624
|
+
memoriesScore: number | null;
|
|
1625
|
+
connectionsScore: number | null;
|
|
1626
|
+
matchedProperties: {
|
|
1627
|
+
name: string;
|
|
1628
|
+
value: string;
|
|
1629
|
+
similarity: number;
|
|
1630
|
+
}[];
|
|
1631
|
+
matchedMemorySnippets: {
|
|
1632
|
+
seedSnippet: string;
|
|
1633
|
+
matchSnippet: string;
|
|
1634
|
+
score: number;
|
|
1635
|
+
}[];
|
|
1636
|
+
sharedConnections: {
|
|
1637
|
+
persons: string[];
|
|
1638
|
+
entities: string[];
|
|
1639
|
+
keywords: string[];
|
|
1640
|
+
} | null;
|
|
1641
|
+
};
|
|
1642
|
+
}
|
|
1643
|
+
export interface SimilarResponse {
|
|
1644
|
+
seed: {
|
|
1645
|
+
recordId: string;
|
|
1646
|
+
type: string;
|
|
1647
|
+
label: string;
|
|
1648
|
+
vectorsUsed: number;
|
|
1649
|
+
};
|
|
1650
|
+
results?: SimilarResult[];
|
|
1651
|
+
tiers?: Record<string, string[]>;
|
|
1652
|
+
allIds?: {
|
|
1653
|
+
recordId: string;
|
|
1654
|
+
score: number;
|
|
1655
|
+
tier: string;
|
|
1656
|
+
}[];
|
|
1657
|
+
tierSummary?: Record<string, number>;
|
|
1658
|
+
totalMatches: number;
|
|
1659
|
+
metadata: Record<string, unknown>;
|
|
1660
|
+
warning?: string;
|
|
1661
|
+
usage: {
|
|
1662
|
+
credits: number;
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
/** Options for POST /api/v1/segment -- bucket records into similarity tiers. */
|
|
1666
|
+
export interface SegmentOptions {
|
|
1667
|
+
/** Seed: record identifier OR text. Text creates a text-based seed. */
|
|
1668
|
+
seed: {
|
|
1669
|
+
recordId?: string;
|
|
1670
|
+
email?: string;
|
|
1671
|
+
websiteUrl?: string;
|
|
1672
|
+
customKeyName?: string;
|
|
1673
|
+
customKeyValue?: string;
|
|
1674
|
+
/** Free-form text seed (e.g., "Enterprise SaaS CTO"). Segment only. */
|
|
1675
|
+
text?: string;
|
|
1676
|
+
};
|
|
1677
|
+
/** Entity type (default: 'contact'). */
|
|
1678
|
+
type?: string;
|
|
1679
|
+
/** What dimensions drive similarity. Default: 'hybrid'. No 'connections' for segment. */
|
|
1680
|
+
dimensions?: 'properties' | 'memories' | 'hybrid';
|
|
1681
|
+
/** Fine-tune which properties matter. */
|
|
1682
|
+
dimensionFilters?: {
|
|
1683
|
+
propertyNames?: string[];
|
|
1684
|
+
collectionIds?: string[];
|
|
1685
|
+
systemNames?: string[];
|
|
1686
|
+
};
|
|
1687
|
+
/** Scope to candidate records. */
|
|
1688
|
+
candidatePool?: {
|
|
1689
|
+
type?: string;
|
|
1690
|
+
collectionIds?: string[];
|
|
1691
|
+
};
|
|
1692
|
+
/** Override tier thresholds. */
|
|
1693
|
+
tierThresholds?: {
|
|
1694
|
+
very_similar?: number;
|
|
1695
|
+
similar?: number;
|
|
1696
|
+
};
|
|
1697
|
+
/** Min similarity threshold (default: 0.3). */
|
|
1698
|
+
minScore?: number;
|
|
1699
|
+
/** Max recordIds per tier page (default: 50, max: 500). */
|
|
1700
|
+
maxPerTier?: number;
|
|
1701
|
+
/** Skip N recordIds per tier for pagination (default: 0). */
|
|
1702
|
+
tierOffset?: number;
|
|
1703
|
+
/** Fetch only one tier. */
|
|
1704
|
+
returnTier?: 'very_similar' | 'similar' | 'somewhat_similar';
|
|
1705
|
+
}
|
|
1706
|
+
export interface SegmentTier {
|
|
1707
|
+
count: number;
|
|
1708
|
+
recordIds: string[];
|
|
1709
|
+
scoreRange: {
|
|
1710
|
+
min: number;
|
|
1711
|
+
max: number;
|
|
1712
|
+
};
|
|
1713
|
+
hasMore: boolean;
|
|
1714
|
+
approximate?: boolean;
|
|
1715
|
+
}
|
|
1716
|
+
export interface SegmentResponse {
|
|
1717
|
+
seed: {
|
|
1718
|
+
recordId: string | null;
|
|
1719
|
+
type: string;
|
|
1720
|
+
label: string;
|
|
1721
|
+
vectorsUsed: number;
|
|
1722
|
+
};
|
|
1723
|
+
tiers: Record<string, SegmentTier>;
|
|
1724
|
+
totalRecords: number;
|
|
1725
|
+
metadata: Record<string, unknown>;
|
|
1726
|
+
usage: {
|
|
1727
|
+
credits: number;
|
|
1728
|
+
};
|
|
1729
|
+
}
|