@usecortex_ai/node 0.5.1 → 0.5.2
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/README.md +86 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ You can consider a `tenant` as a single database that can have internal isolated
|
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
43
|
async function createTenant() {
|
|
44
|
-
const tenantCreationResponse = await client.
|
|
44
|
+
const tenantCreationResponse = await client.tenant.create({
|
|
45
45
|
tenant_id: "my-company"
|
|
46
46
|
});
|
|
47
47
|
return tenantCreationResponse;
|
|
@@ -53,60 +53,101 @@ async function createTenant() {
|
|
|
53
53
|
When you index your data, you make it ready for retrieval from Cortex using natural language.
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
// Add to your knowledge base
|
|
57
|
+
import fs from 'fs';
|
|
58
|
+
|
|
59
|
+
const uploadResult = await client.upload.knowledge({
|
|
60
|
+
files: [
|
|
61
|
+
fs.readFileSync("a.pdf"),
|
|
62
|
+
fs.readFileSync("b.pdf")
|
|
63
|
+
],
|
|
64
|
+
tenant_id: "tenant_123",
|
|
65
|
+
file_metadata: [
|
|
66
|
+
{
|
|
67
|
+
id: "doc_a",
|
|
68
|
+
tenant_metadata: { dept: "sales" },
|
|
69
|
+
document_metadata: { author: "Alice" },
|
|
70
|
+
relations: false
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "doc_b",
|
|
74
|
+
tenant_metadata: { dept: "marketing" },
|
|
75
|
+
document_metadata: { author: "Bob" },
|
|
76
|
+
relations: true
|
|
65
77
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Upload a document file
|
|
71
|
-
async function uploadFile() {
|
|
72
|
-
const uploadResult = await client.upload.uploadDocument({
|
|
73
|
-
file: fs.readFileSync("company-handbook.pdf"),
|
|
74
|
-
tenant_id: "my-company",
|
|
75
|
-
sub_tenant_id: "hr",
|
|
76
|
-
file_id: "doc_q1_summary"
|
|
77
|
-
});
|
|
78
|
-
return uploadResult;
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
> **For a more detailed explanation** of document upload, including supported file formats, processing pipeline, metadata handling, and advanced configuration options, refer to the [Upload Document endpoint documentation](https://docs.usecortex.ai/api-reference/endpoint/upload-document).
|
|
78
|
+
]
|
|
79
|
+
});
|
|
83
80
|
|
|
84
|
-
|
|
81
|
+
// Index user memories
|
|
82
|
+
const result = await client.userMemory.add({
|
|
83
|
+
memories: [
|
|
84
|
+
{
|
|
85
|
+
text: "User prefers detailed explanations and dark mode",
|
|
86
|
+
infer: true,
|
|
87
|
+
user_name: "John"
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
tenant_id: "tenant-01",
|
|
91
|
+
sub_tenant_id: "",
|
|
92
|
+
upsert: true
|
|
93
|
+
});
|
|
85
94
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
// Markdown content
|
|
96
|
+
const markdownResult = await client.userMemory.add({
|
|
97
|
+
memories: [
|
|
98
|
+
{
|
|
99
|
+
text: "# Meeting Notes\n\n## Key Points\n- Budget approved\n- Launch date: Q2",
|
|
100
|
+
is_markdown: true,
|
|
101
|
+
infer: false,
|
|
102
|
+
title: "Meeting Notes"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
tenant_id: "tenant-01",
|
|
106
|
+
sub_tenant_id: "",
|
|
107
|
+
upsert: true
|
|
93
108
|
});
|
|
94
109
|
|
|
95
|
-
//
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
// User-assistant pairs with inference
|
|
111
|
+
const conversationResult = await client.userMemory.add({
|
|
112
|
+
memories: [
|
|
113
|
+
{
|
|
114
|
+
user_assistant_pairs: [
|
|
115
|
+
{ user: "What are my preferences?", assistant: "You prefer dark mode and detailed explanations." },
|
|
116
|
+
{ user: "How do I like my reports?", assistant: "You prefer weekly summary reports with charts." }
|
|
117
|
+
],
|
|
118
|
+
infer: true,
|
|
119
|
+
user_name: "John",
|
|
120
|
+
custom_instructions: "Extract user preferences"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
tenant_id: "tenant-01",
|
|
124
|
+
sub_tenant_id: "",
|
|
125
|
+
upsert: true
|
|
99
126
|
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
> **For a more detailed explanation** of document upload, including supported file formats, processing pipeline, metadata handling, and advanced configuration options, refer to the [Ingest Knowledge](https://docs.usecortex.ai/api-reference/endpoint/add-knowledge-memories).
|
|
100
130
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
131
|
+
### Search
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
// Search across memories/knowledge base
|
|
135
|
+
const results = await client.recall.fullRecall({
|
|
136
|
+
query: "Which mode does user prefer",
|
|
137
|
+
tenantId: "tenant_1234",
|
|
138
|
+
subTenantId: "sub_tenant_4567",
|
|
139
|
+
alpha: 0.8,
|
|
140
|
+
recencyBias: 0
|
|
141
|
+
});;
|
|
142
|
+
|
|
143
|
+
// List all the data (memories + knowledge base)
|
|
144
|
+
const allSources = await client.data.listData({
|
|
145
|
+
tenant_id: "tenant_1234",
|
|
146
|
+
sub_tenant_id: "sub_tenant_4567"
|
|
106
147
|
});
|
|
107
148
|
```
|
|
108
149
|
|
|
109
|
-
> **For a more detailed explanation** of search and retrieval, including query parameters, scoring mechanisms, result structure, and advanced search features, refer to the [
|
|
150
|
+
> **For a more detailed explanation** of search and retrieval, including query parameters, scoring mechanisms, result structure, and advanced search features, refer to the [Recall endpoint documentation](https://docs.usecortex.ai/api-reference/endpoint/smart).
|
|
110
151
|
|
|
111
152
|
## SDK Method Structure & Type Safety
|
|
112
153
|
|
package/package.json
CHANGED