diff --git a/sdk/collections.mdx b/sdk/collections.mdx index d2140007..6c8fb896 100644 --- a/sdk/collections.mdx +++ b/sdk/collections.mdx @@ -1,18 +1,17 @@ --- title: Collections -description: "Add basic storage and search capabilities to your functions." +description: "Add storage and vector search capabilities to your functions." --- {/* */} +Add storage and vector search capabilities to your functions using Hypermode Collections. +A Collection is a built-in storage that supports vector embeddings. -Hypermode Collections provide a built-in key-value storage mechanism that supports vector -embeddings, that you can use from your functions. After [defining collections](../define-collections) -in your project's manifest, you can use the following APIs to interact with the data. +Hypermode allows you to [define collections](../define-collections) and interact with them through an easy-to-use API. ## Example project -For your reference, A complete example for using the Collections APIs is available on GitHub in the -`hypermodeinc/functions-as` repository, at [/examples/collection](https://github.com/hypermodeinc/functions-as/tree/main/examples/collection). +To see Collections in action, explore the [example project](https://github.com/hypermodeinc/functions-as/tree/main/examples/collection) on GitHub. This example demonstrates how to manage a collection of products using Hypermode's Collections and Models APIs, covering core create,read,update, and delete operations, embedding usage, search capabilities, and vector-based comparisons. ## Import from the SDK @@ -41,11 +40,11 @@ The APIs in the `collections` namespace are below, organized by category. #### upsert -Inserts or updates an item into a collection. +Inserts or updates an item in a collection. - If an item with the same key already exists, the original text is overwritten - with the new text. + If the item already exists, the function overwrites the previous value. If not, + it creates a new one. ```go @@ -63,8 +62,8 @@ collections.upsert( - An optional key for the item. If `null`, Hypermode assigns a new UUID as the - key for the item. + The unique identifier for the item in the namespace. If null, the function + generates a unique identifier. @@ -76,7 +75,8 @@ collections.upsert( - An optional namespace to associate with the item. + Associates the item with a specific namespace. Defaults to an empty namespace + if not provided. #### upsertBatch @@ -116,7 +116,8 @@ collections.upsertBatch( - An optional namespace to associate with the items. + Associates the item with a specific namespace. Defaults to an empty namespace + if not provided. #### remove @@ -140,14 +141,15 @@ collections.remove( - An optional namespace to associate with the item. + The namespace to remove the item from. Defaults to the default namespace if + not provided. ### Search and Retrieval Functions #### search -Search for an item in the collection by using natural language 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. Hypermode uses the same embedder for both inserting text into the collection, @@ -186,12 +188,13 @@ collections.search( - An optional array of namespaces to search within. + A list of namespaces to search the item from. Defaults to the default + namespace if not provided. #### searchByVector -Search for an item in the collection by using a vector. +Perform a vector-based search on a collection, which is helpful for scenarios requiring precise similarity calculations between pre-computed embeddings. Hypermode uses the same embedder for both inserting text into the collection, @@ -259,7 +262,8 @@ Classify an item in the collection using previous vectors' labels. - An optional namespace to associate with the item. + The namespace to search the items from. Defaults to the default namespace if + not provided. #### computeDistance @@ -289,7 +293,8 @@ collections.computeDistance( - An optional namespace to associate with the item. + The namespace to search the items from. Defaults to the default namespace if + not provided. #### getText @@ -313,7 +318,8 @@ collections.getText( - An optional namespace to associate with the item. + The namespace to get the item from. Defaults to the default namespace if not + provided. #### getTexts @@ -333,7 +339,8 @@ collections.getTexts( - An optional namespace to associate with the item. + The namespace to get the items from. Defaults to the default namespace if not + provided. #### getNamespaces @@ -376,7 +383,8 @@ collections.getVector( - An optional namespace to associate with the item. + The namespace to get the item from. Defaults to the default namespace if not + provided. #### getLabels @@ -400,14 +408,16 @@ collections.getLabels( - An optional namespace to associate with the item. + The namespace to get the item from. Defaults to the default namespace if not + provided. ### Maintenance Functions #### recomputeSearchMethod -Recomputes the embeddings for all texts in a collection, for a specific search method. +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. ```go collections.recomputeSearchMethod( @@ -426,7 +436,7 @@ collections.recomputeSearchMethod( - An optional namespace to associate with the item. + The namespace to use. Defaults to the default namespace if not provided. ### Objects @@ -459,7 +469,8 @@ Represents the result of a mutation operation on a collection. - Whether the operation was successful. + A boolean indicating whether the operation completed successfully. Use this to + confirm success before handling the result. @@ -498,7 +509,8 @@ Represents the result of a search operation on a collection. - Whether the operation was successful. + A boolean indicating whether the operation completed successfully. Use this to + confirm success before handling the result. @@ -573,7 +585,8 @@ Represents the result of a classification operation on a collection. - Whether the operation was successful. + A boolean indicating whether the operation completed successfully. Use this to + confirm success before handling the result. @@ -683,7 +696,8 @@ Represents the result of a mutation operation on a search method. - Whether the operation was successful. + A boolean indicating whether the operation completed successfully. Use this to + confirm success before handling the result.