# EmbeddingStore

## Overview

EmbeddingStore provides methods to embed text data and perform similarity search using embeddings. It supports asynchronous embedding and blocking search, and can be backed by various embedding store implementations.

## Methods Summarized

| Type                                                                           | Name                                                                                                                                              | Summary                                                                                                                                                                                                                                      |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) | [embed(pdfSource, maxSegmentSizeInChars, maxOverlapSizeInChars)](#embed-pdfsource-maxsegmentsizeinchars-maxoverlapsizeinchars)                    | Embeds a PDF document by splitting it into paragraphs of specified size and overlap The text segments are stored in the embedding store and will get metadata from the pdf and if possible also the name of the PDF is set if that is known. |
| [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) | [embed(pdfSource, maxSegmentSizeInChars, maxOverlapSizeInChars, metaData)](#embed-pdfsource-maxsegmentsizeinchars-maxoverlapsizeinchars-metadata) | Embeds a PDF document by splitting it into paragraphs of specified size and overlap, with metadata.                                                                                                                                          |
| [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) | [embed(data, metaData)](#embed-data-metadata)                                                                                                     | Asynchronously embeds an array of text data with optional metadata and stores the results.                                                                                                                                                   |
| [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) | [embedAll(foundSet, textColumns)](#embedall-foundset-textcolumns)                                                                                 | Generates embeddings for all records in the specified foundSet for the given textColumns and stores them in the specified vector column.                                                                                                     |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [search(text)](#search-text)                                                                                                                      | Performs a blocking similarity search for the given text, returning the best matches from the store.                                                                                                                                         |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [search(text, maxResults)](#search-text-maxresults)                                                                                               | Performs a blocking similarity search for the given text, returning the best matches from the store.                                                                                                                                         |

## Methods Detailed

### embed(pdfSource, maxSegmentSizeInChars, maxOverlapSizeInChars)

Embeds a PDF document by splitting it into paragraphs of specified size and overlap The text segments are stored in the embedding store and will get metadata from the pdf and if possible also the name of the PDF is set if that is known.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **pdfSource** This can be JSFile or String represeting a file\
  &#x20;                            path, or byte\[] representing the PDF content.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **maxSegmentSizeInChars** How many characters per segment we can have.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **maxOverlapSizeInChars** How many characters of overlap between segments.

**Returns:** [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) A Promise resolving to the store

### embed(pdfSource, maxSegmentSizeInChars, maxOverlapSizeInChars, metaData)

Embeds a PDF document by splitting it into paragraphs of specified size and overlap, with metadata. The text segments are stored in the embedding store and will get metadata from the pdf and if possible also the name of the PDF is set if that is known. Also additional metadata can be provided that will be attached to each segment.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **pdfSource** This can be JSFile or String represeting a file\
  &#x20;                            path, or byte\[] representing the PDF content.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **maxSegmentSizeInChars** How many characters per segment we can have.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **maxOverlapSizeInChars** How many characters of overlap between segments.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **metaData** Metadata to attach to each segment.

**Returns:** [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) A Promise resolving to the store

### embed(data, metaData)

Asynchronously embeds an array of text data with optional metadata and stores the results.

**Parameters**

* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **data** The array of text strings to embed.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **metaData** An array of metadata maps, one for each text string (may be\
  &#x20;               null).

**Returns:** [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) A Promise resolving to the store

### embedAll(foundSet, textColumns)

Generates embeddings for all records in the specified foundSet for the given textColumns and stores them in the specified vector column.

**Parameters**

* [JSFoundSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsfoundset) **foundSet** records in the foundSet are embedded
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **textColumns** columns of the foundSet to embed

**Returns:** [Promise](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/promise) A Promise resolving with the given foundSet when embeddings are\
&#x20;       stored, or rejects on error.

### search(text)

Performs a blocking similarity search for the given text, returning the best matches from the store. This returns the default 3 results

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** The query text to search for.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) An array of SearchResult objects representing the best matches.

### search(text, maxResults)

Performs a blocking similarity search for the given text, returning the best matches from the store.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** The query text to search for.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **maxResults** The maximum number of results to return.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) An array of SearchResult objects representing the best matches.

***
