add()
Uploads your documents to Memora
This page serves as a guide on how to use the add()
method in Memora. Before moving on, it’s a good idea to familiarize yourself with our main documents and collections pages.
Basic usage
Here’s how you can use the add()
method to upload a document to Memora:
In the above example, we added a document to Memora that:
- doesn’t contain any metadata;
- is stored in the default collection.
Syntax
Parameters
This represents the text content of your document. Memora uses this content for document retrieval.
If you pass an array of strings, Memora will use its batch mode to insert multiple documents simultaneously.
Even in batch mode, each insertion counts as a single request. For Hobby plan users, there’s a rate limit of 30 requests per minute. Therefore, you cannot perform more than 30 insertions at a time if you’re on the Hobby plan.
To learn more about limits, click here.
Return value
When you use the add()
method, it returns the following:
Adding documents to a collection
Documents are always stored inside a collection. In the previous examples, we didn’t specify the collection, so the documents were added to your account’s default collection.
Example
Specifying a collection is simple: just use the on()
method before calling add()
.
The on()
method can be used even in batch mode.
Syntax
Parameters
This is the collection name to which you want to add the document. If no collection exists with the supplied name, Memora will create a new one for you and insert the document into it.
Collection name
Certain rules apply when naming your collection. Here’s what you can include:
Name | Example |
---|---|
English letters | abcXYZ |
Numbers | abc123XYZ |
Special characters (_, -, ., @ and :) | @abc.1:23-XYZ_ |
Adding metadata
Documents can also have also have metadata. You can pass any object as metadata.
Example
Here’s an example of adding a document with metadata into Memora:
Syntax
Parameters
This is the metadata associated with the document you’re adding to Memora.
This is an array of metadata objects, each corresponding in order to the documents you’re adding in batch mode with add()
.
Example: Adding multiple documents with metadata
Wrapping up
That’s all you need to know about the add()
method for now. With this knowledge, you should be able to easily add documents, complete with metadata, to any collection in Memora.
In the next section, we will explore the find()
method, which is how you retrieve documents from your collections in Memora.
If you have any more questions or need further clarification, feel free to reach out to us through our support channels.
Was this page helpful?