@@ -43,43 +43,12 @@ const client = new Supermemory({
4343 apiKey: process .env [' SUPERMEMORY_API_KEY' ], // This is the default and can be omitted
4444});
4545
46- const params: Supermemory .MemoryAddParams = {
47- content: ' This is a detailed article about machine learning concepts...' ,
48- };
49- const response: Supermemory .MemoryAddResponse = await client .memories .add (params );
46+ const params: Supermemory .SearchDocumentsParams = { q: ' machine learning concepts' };
47+ const response: Supermemory .SearchDocumentsResponse = await client .search .documents (params );
5048```
5149
5250Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
5351
54- ## File uploads
55-
56- Request parameters that correspond to file uploads can be passed in many different forms:
57-
58- - ` File ` (or an object with the same structure)
59- - a ` fetch ` ` Response ` (or an object with the same structure)
60- - an ` fs.ReadStream `
61- - the return value of our ` toFile ` helper
62-
63- ``` ts
64- import fs from ' fs' ;
65- import Supermemory , { toFile } from ' supermemory' ;
66-
67- const client = new Supermemory ();
68-
69- // If you have access to Node `fs` we recommend using `fs.createReadStream()`:
70- await client .memories .uploadFile ({ file: fs .createReadStream (' /path/to/file' ) });
71-
72- // Or if you have the web `File` API you can pass a `File` instance:
73- await client .memories .uploadFile ({ file: new File ([' my bytes' ], ' file' ) });
74-
75- // You can also pass a `fetch` `Response`:
76- await client .memories .uploadFile ({ file: await fetch (' https://somesite/file' ) });
77-
78- // Finally, if none of the above are convenient, you can use our `toFile` helper:
79- await client .memories .uploadFile ({ file: await toFile (Buffer .from (' my bytes' ), ' file' ) });
80- await client .memories .uploadFile ({ file: await toFile (new Uint8Array ([0 , 1 , 2 ]), ' file' ) });
81- ```
82-
8352## Handling errors
8453
8554When the library is unable to connect to the API,
@@ -88,17 +57,15 @@ a subclass of `APIError` will be thrown:
8857
8958<!-- prettier-ignore -->
9059``` ts
91- const response = await client .memories
92- .add ({ content: ' This is a detailed article about machine learning concepts...' })
93- .catch (async (err ) => {
94- if (err instanceof Supermemory .APIError ) {
95- console .log (err .status ); // 400
96- console .log (err .name ); // BadRequestError
97- console .log (err .headers ); // {server: 'nginx', ...}
98- } else {
99- throw err ;
100- }
101- });
60+ const response = await client .search .documents ({ q: ' machine learning concepts' }).catch (async (err ) => {
61+ if (err instanceof Supermemory .APIError ) {
62+ console .log (err .status ); // 400
63+ console .log (err .name ); // BadRequestError
64+ console .log (err .headers ); // {server: 'nginx', ...}
65+ } else {
66+ throw err ;
67+ }
68+ });
10269```
10370
10471Error codes are as follows:
@@ -130,7 +97,7 @@ const client = new Supermemory({
13097});
13198
13299// Or, configure per-request:
133- await client .memories . add ({ content : ' This is a detailed article about machine learning concepts... ' }, {
100+ await client .search . documents ({ q : ' machine learning concepts' }, {
134101 maxRetries: 5 ,
135102});
136103```
@@ -147,7 +114,7 @@ const client = new Supermemory({
147114});
148115
149116// Override per-request:
150- await client .memories . add ({ content : ' This is a detailed article about machine learning concepts... ' }, {
117+ await client .search . documents ({ q : ' machine learning concepts' }, {
151118 timeout: 5 * 1000 ,
152119});
153120```
@@ -170,17 +137,15 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
170137``` ts
171138const client = new Supermemory ();
172139
173- const response = await client .memories
174- .add ({ content: ' This is a detailed article about machine learning concepts...' })
175- .asResponse ();
140+ const response = await client .search .documents ({ q: ' machine learning concepts' }).asResponse ();
176141console .log (response .headers .get (' X-My-Header' ));
177142console .log (response .statusText ); // access the underlying Response object
178143
179- const { data : response, response : raw } = await client .memories
180- .add ({ content : ' This is a detailed article about machine learning concepts... ' })
144+ const { data : response, response : raw } = await client .search
145+ .documents ({ q : ' machine learning concepts' })
181146 .withResponse ();
182147console .log (raw .headers .get (' X-My-Header' ));
183- console .log (response .id );
148+ console .log (response .results );
184149```
185150
186151### Logging
0 commit comments