@@ -43,40 +43,12 @@ const client = new Supermemory({
43
43
apiKey: process .env [' SUPERMEMORY_API_KEY' ], // This is the default and can be omitted
44
44
});
45
45
46
- const response: Supermemory .MemoryAddResponse = await client .memories .add ();
46
+ const params: Supermemory .SearchDocumentsParams = { q: ' machine learning concepts' };
47
+ const response: Supermemory .SearchDocumentsResponse = await client .search .documents (params );
47
48
```
48
49
49
50
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
50
51
51
- ## File uploads
52
-
53
- Request parameters that correspond to file uploads can be passed in many different forms:
54
-
55
- - ` File ` (or an object with the same structure)
56
- - a ` fetch ` ` Response ` (or an object with the same structure)
57
- - an ` fs.ReadStream `
58
- - the return value of our ` toFile ` helper
59
-
60
- ``` ts
61
- import fs from ' fs' ;
62
- import Supermemory , { toFile } from ' supermemory' ;
63
-
64
- const client = new Supermemory ();
65
-
66
- // If you have access to Node `fs` we recommend using `fs.createReadStream()`:
67
- await client .memories .uploadFile ({ file: fs .createReadStream (' /path/to/file' ) });
68
-
69
- // Or if you have the web `File` API you can pass a `File` instance:
70
- await client .memories .uploadFile ({ file: new File ([' my bytes' ], ' file' ) });
71
-
72
- // You can also pass a `fetch` `Response`:
73
- await client .memories .uploadFile ({ file: await fetch (' https://somesite/file' ) });
74
-
75
- // Finally, if none of the above are convenient, you can use our `toFile` helper:
76
- await client .memories .uploadFile ({ file: await toFile (Buffer .from (' my bytes' ), ' file' ) });
77
- await client .memories .uploadFile ({ file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ) });
78
- ```
79
-
80
52
## Handling errors
81
53
82
54
When the library is unable to connect to the API,
@@ -85,7 +57,7 @@ a subclass of `APIError` will be thrown:
85
57
86
58
<!-- prettier-ignore -->
87
59
``` ts
88
- const response = await client .memories . add ( ).catch (async (err ) => {
60
+ const response = await client .search . documents ({ q: ' machine learning concepts ' } ).catch (async (err ) => {
89
61
if (err instanceof Supermemory .APIError ) {
90
62
console .log (err .status ); // 400
91
63
console .log (err .name ); // BadRequestError
@@ -125,7 +97,7 @@ const client = new Supermemory({
125
97
});
126
98
127
99
// Or, configure per-request:
128
- await client .memories . add ( {
100
+ await client .search . documents ({ q : ' machine learning concepts ' }, {
129
101
maxRetries: 5 ,
130
102
});
131
103
```
@@ -142,7 +114,7 @@ const client = new Supermemory({
142
114
});
143
115
144
116
// Override per-request:
145
- await client .memories . add ( {
117
+ await client .search . documents ({ q: ' machine learning concepts ' }, {
146
118
timeout: 5 * 1000 ,
147
119
});
148
120
```
@@ -165,13 +137,15 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
165
137
``` ts
166
138
const client = new Supermemory ();
167
139
168
- const response = await client .memories . add ( ).asResponse ();
140
+ const response = await client .search . documents ({ q: ' machine learning concepts ' } ).asResponse ();
169
141
console .log (response .headers .get (' X-My-Header' ));
170
142
console .log (response .statusText ); // access the underlying Response object
171
143
172
- const { data : response, response : raw } = await client .memories .add ().withResponse ();
144
+ const { data : response, response : raw } = await client .search
145
+ .documents ({ q: ' machine learning concepts' })
146
+ .withResponse ();
173
147
console .log (raw .headers .get (' X-My-Header' ));
174
- console .log (response .id );
148
+ console .log (response .results );
175
149
```
176
150
177
151
### Logging
0 commit comments