Collections APIs
Add storage and vector search capabilities to your functions.
While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.
Modus Collections APIs documentation is available on the following pages:
- AssemblyScript Collections APIs
- Go Collections APIs (this page)
The Modus Collection APIs allow you to add vector search within your functions.
Import
To begin, import the collections
package from the SDK:
Collections APIs
The APIs in the collections
package are below, organized by category.
We’re constantly introducing new APIs through ongoing development with early users. Please open an issue if you have ideas on what would make Modus even more powerful for your next app!
Mutation Functions
Upsert
Inserts or updates an item in a collection.
If the item already exists, the function overwrites the previous value. If not, it creates a new one.
Name of the collection, as defined in the manifest.
The unique identifier for the item in the namespace. If nil
, the function
generates a unique identifier.
The text of the item to add to the collection.
An optional slice of labels to associate with the item.
Associates the item with a specific namespace. Defaults to an empty namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
UpsertBatch
Inserts or updates a batch of items into a collection.
If an item with the same key already exists, the original text is overwritten with the new text.
Name of the collection, as defined in the manifest.
Slice of keys for the item to add to the collection. If you pass nil
for any
key, Hypermode assigns a new UUID as the key for the item.
Slice of texts for the items to add to the collection.
An optional slice of slices of labels to associate with the items.
Associates the item with a specific namespace. Defaults to an empty namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
Remove
Removes an item from the collection.
Name of the collection, as defined in the manifest.
The key of the item to delete from the collection.
The namespace to remove the item from. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
Search and Retrieval Functions
ComputeDistance
Computes distance between two keys in a collection using a search method’s embedder.
Name of the collection, as defined in the manifest.
The search method used to calculate embedding for key’s texts.
Keys to compute similarity on.
The namespace to search the items from. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
NnClassify
Classify an item in the collection using previous vectors’ labels.
Name of the collection, as defined in the manifest.
The search method used to calculate embedding for text & search against.
The text to compute natural language search on.
The namespace to search the items from. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
GetLabels
Get the labels for an item in a collection.
Name of the collection, as defined in the manifest.
The key of the item to retrieve.
The namespace to get the item from. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
GetNamespaces
Get all namespaces in a collection.
Name of the collection, as defined in the manifest.
GetText
Gets an item’s text from a collection, give the item’s key.
Name of the collection, as defined in the manifest.
The key of the item to retrieve.
The namespace to get the item from. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
GetTexts
Get all items from a collection. The result is a map of key to text for all items in the collection.
Name of the collection, as defined in the manifest.
The namespace to get the items from. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
GetVector
Get the vector for an item in a collection.
Name of the collection, as defined in the manifest.
The search method used to calculate embedding for key’s texts.
The key of the item to retrieve.
The namespace to get the item from. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
Search
Perform a natural language search on items within a collection. This method is useful for finding items that match a search query based on semantic meaning.
Modus uses the same embedder for both inserting text into the collection, and for the text used when searching the collection.
Name of the collection, as defined in the manifest.
The search method used to calculate embedding for text & search against.
The text to compute natural language search on.
Additional options for the search:
collections.WithLimit(limit int)
: The number of result objects to return.collections.WithReturnText(returnText bool)
: A flag to return the texts in the response.collections.WithNamespaces(namespaces []string)
: A list of namespaces to search the item from. Defaults to the default namespace if not provided.
SearchByVector
Perform a vector-based search on a collection, which is helpful for scenarios requiring precise similarity calculations between pre-computed embeddings.
Modus uses the same embedder for both inserting text into the collection, and for the vector used when searching the collection.
Name of the collection, as defined in the manifest.
The search method used to calculate embedding for vector & search against.
The vector to compute search on.
Additional options for the search:
collections.WithLimit(limit int)
: The number of result objects to return.collections.WithReturnText(returnText bool)
: A flag to return the texts in the response.collections.WithNamespaces(namespaces []string)
: A list of namespaces to search the item from. Defaults to the default namespace if not provided.
Maintenance Functions
RecomputeSearchMethod
Recalculates the embeddings for all items in a collection. It can be resource-intensive, use it when necessary, for example after you have updated the method for embedding calculation and want to re-compute the embeddings for existing data in the collection.
Name of the collection, as defined in the manifest.
The search method to recompute embeddings for.
The namespace to use. Defaults to the default namespace if not provided.
Pass collections.WithNamespace("namespace")
to specify a namespace.
Types
CollectionClassificationLabelObject
Represents a classification label.
The classification label.
The confidence score of the classification label.
CollectionClassificationResult
Represents the result of a classification operation on a collection.
Name of the collection.
The status of the operation.
Error message, if any.
The search method used in the operation.
The classification labels.
The classification results.
CollectionClassificationResultObject
Represents an object in the classification results.
The key of the item classified.
The classification labels.
The distance of the item from the classification labels.
The similarity score of the item classified.
CollectionMutationResult
Represents the result of a mutation operation on a collection.
Name of the collection.
The status of the operation.
Error message, if any.
The operation performed.
The keys of the items affected by the operation.
CollectionSearchResult
Represents the result of a search operation on a collection.
Name of the collection.
The status of the operation.
Error message, if any.
The search method used in the operation.
The search results.
CollectionSearchResultObject
Represents an object in the search results.
The namespace of the item found as part of the search.
The key of the item found as part of the search.
The text of the item found as part of the search.
The distance of the item from the search text.
The similarity score of the item found, as it pertains to the search.
CollectionStatus
The status of a collection operation.
SearchMethodMutationResult
Represents the result of a mutation operation on a search method.
Name of the collection.
The status of the operation.
Error message, if any.
The operation performed.
The search method affected by the operation.
Was this page helpful?