@usecortex_ai/node 0.3.1 → 0.3.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 +127 -2
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -2,14 +2,139 @@
|
|
|
2
2
|
|
|
3
3
|
The official TypeScript SDK for the Cortex AI platform. Build powerful, context-aware AI applications in your Node.js or TypeScript projects.
|
|
4
4
|
|
|
5
|
+
**Cortex** is your plug-and-play memory infrastructure. It powers intelligent, context-aware retrieval for any AI app or agent. Whether you’re building a customer support bot, research copilot, or internal knowledge assistant - Cortex handles all!
|
|
6
|
+
|
|
7
|
+
[Learn more about the SDK from our docs](https://docs.usecortex.ai/)
|
|
8
|
+
|
|
9
|
+
## Core features
|
|
10
|
+
|
|
11
|
+
* **Dynamic retrieval and querying** that always retrieve the most relevant context
|
|
12
|
+
* **Built-in long-term memory** that evolves with every user interaction
|
|
13
|
+
* **Personalization hooks** for user preferences, intent, and history
|
|
14
|
+
* **Developer-first SDK** with the most flexible APIs and fine-grained controls
|
|
15
|
+
|
|
16
|
+
## Getting started
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm i @usecortex_ai/node
|
|
22
|
+
# or
|
|
23
|
+
yarn add @usecortex_ai/node
|
|
24
|
+
# or
|
|
25
|
+
pnpm add @usecortex_ai/node
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Client setup
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { CortexAIClient } from "@usecortex_ai/node";
|
|
32
|
+
|
|
33
|
+
const client = new CortexAIClient({
|
|
34
|
+
token: process.env.CORTEX_API_KEY,
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Create a Tenant
|
|
39
|
+
|
|
40
|
+
You can consider a `tenant` as a single database that can have internal isolated collections called `sub-tenants`. [Know more about the concept of tenant here](https://docs.usecortex.ai/essentials/multi-tenant)
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
async function createTenant() {
|
|
44
|
+
const tenantCreationResponse = await client.user.createTenant({
|
|
45
|
+
tenant_id: "my-company"
|
|
46
|
+
});
|
|
47
|
+
return tenantCreationResponse;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Index Your Data
|
|
52
|
+
|
|
53
|
+
When you index your data, you make it ready for retrieval from Cortex using natural language.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// Upload text content
|
|
57
|
+
async function uploadText() {
|
|
58
|
+
const res = await client.upload.uploadText({
|
|
59
|
+
tenant_id: "my-company",
|
|
60
|
+
sub_tenant_id: "engineering",
|
|
61
|
+
body: {
|
|
62
|
+
content: "Our API rate limits are 1000 requests per minute for premium accounts.",
|
|
63
|
+
file_id: "api-docs-rate-limits",
|
|
64
|
+
tenant_metadata: { sub_tenant_id: "engineering" }
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return res;
|
|
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).
|
|
83
|
+
|
|
84
|
+
### Search and retrieval
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
// Semantic search with retrieval
|
|
88
|
+
const results = await client.search.retrieve({
|
|
89
|
+
query: "What are the API rate limits?",
|
|
90
|
+
tenant_id: "my-company",
|
|
91
|
+
sub_tenant_id: "engineering",
|
|
92
|
+
max_chunks: 10
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// List all sources
|
|
96
|
+
const allSources = await client.sources.getAll({
|
|
97
|
+
tenant_id: "my-company",
|
|
98
|
+
sub_tenant_id: "engineering"
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Get specific sources by ID
|
|
102
|
+
const specificSources = await client.sources.getByIds({
|
|
103
|
+
tenant_id: "my-company",
|
|
104
|
+
sub_tenant_id: "engineering",
|
|
105
|
+
source_ids: ["api-docs-rate-limits", "company-handbook"]
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
> **For a more detailed explanation** of search and retrieval, including query parameters, scoring mechanisms, result structure, and advanced search features, refer to the [Search endpoint documentation](https://docs.usecortex.ai/api-reference/endpoint/search).
|
|
110
|
+
|
|
111
|
+
## SDK Method Structure & Type Safety
|
|
112
|
+
|
|
113
|
+
Our SDKs follow a predictable pattern that mirrors the API structure while providing full type safety.
|
|
114
|
+
|
|
115
|
+
> **Method Mapping** : `client.<group>.<functionName>` mirrors `api.usecortex.ai/<group>/<function_name>`
|
|
116
|
+
>
|
|
117
|
+
> For example: `client.upload.uploadText()` corresponds to `POST /upload/upload_text`
|
|
118
|
+
|
|
119
|
+
The SDKs provide exact type parity with the API specification:
|
|
120
|
+
|
|
121
|
+
- **Request Parameters** : Every field documented in the API reference (required, optional, types, validation rules) is reflected in the SDK method signatures
|
|
122
|
+
- **Response Objects** : Return types match the exact JSON schema documented for each endpoint
|
|
123
|
+
- **Error Types** : Exception structures mirror the error response formats from the API
|
|
124
|
+
- **Nested Objects** : Complex nested parameters and responses maintain their full structure and typing
|
|
125
|
+
|
|
126
|
+
> This means you can rely on your IDE’s autocomplete and type checking. If a parameter is optional in the API docs, it’s optional in the SDK. If a response contains a specific field, your IDE will know about it. Our SDKs are built in such a way that your IDE will automatically provide **autocompletion, type-checking, inline documentation with examples, and compile time validation** for each and every method.
|
|
127
|
+
>
|
|
128
|
+
> Just hit **Cmd+Space/Ctrl+Space!**
|
|
129
|
+
|
|
5
130
|
## Links
|
|
6
131
|
|
|
7
132
|
- **Homepage:** [usecortex.ai](https://www.usecortex.ai/)
|
|
8
133
|
- **Documentation:** [docs.usecortex.ai](https://docs.usecortex.ai/)
|
|
9
134
|
|
|
10
|
-
##
|
|
135
|
+
## Our docs
|
|
11
136
|
|
|
12
|
-
Please refer to our [
|
|
137
|
+
Please refer to our [API reference](https://docs.usecortex.ai/api-reference/introduction) for detailed explanations of every API endpoint, parameter options, and advanced use cases.
|
|
13
138
|
|
|
14
139
|
## Support
|
|
15
140
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usecortex_ai/node",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "The official TypeScript SDK for the Cortex AI platform.",
|
|
5
5
|
"author": "Nishkarsh Shrivastava <nishkarsh@usecortex.ai>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
-
"private": false,
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/usefindr/cortex-ai-ts.git"
|
|
11
|
-
},
|
|
12
7
|
"main": "./dist/index.js",
|
|
13
8
|
"types": "./dist/index.d.ts",
|
|
14
9
|
"files": [
|
|
15
10
|
"dist"
|
|
16
11
|
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cortex",
|
|
14
|
+
"cortex-ai",
|
|
15
|
+
"cortex-ai-sdk",
|
|
16
|
+
"cortex-ai-typescript-sdk",
|
|
17
|
+
"rag", "gen-ai", "memory", "ai"
|
|
18
|
+
],
|
|
17
19
|
"scripts": {
|
|
18
20
|
"build": "tsc",
|
|
19
21
|
"prepublishOnly": "npm run build"
|