new LocalMemory(embeddingProvider)
Parameters:
Name | Type | Description |
---|---|---|
embeddingProvider |
function | Function to retrieve embeddings |
- Source:
Members
docs :Array.<any>
Type:
- Array.<any>
- Source:
Methods
_serializeEmbs() → {Object|null}
Serializes the embs array to an object representation
- Source:
Returns:
- Serialized embs array or null if embs is empty
- Type
- Object | null
(async) add(doc, keyopt)
Adds a document to memory along with its key (or uses the document as the key) Retrieves the embedding using the embeddingProvider Stores the embedding in the embs ndarray and the document in the docs array
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
doc |
string | Document to add |
||
key |
string | null |
<optional> |
null | Key for the document (optional) |
- Source:
clear()
Clears the memory
- Source:
(async) get(query, k) → {Promise.<(Array.<string>|Array.<any>)>}
This function takes a query and a value k, retrieves embeddings for the query, calculates scores for stored embeddings, and returns the top k documents based on the scores.
Parameters:
Name | Type | Description |
---|---|---|
query |
string | The query parameter is the input query for which the function will retrieve the top k most similar documents. |
k |
number |
|
- Source:
Returns:
The function get
returns an array of documents that are most similar to the input
query, based on their embeddings. The number of documents returned is determined by the value of
the k
parameter. If there are no embeddings stored or they are not in the expected format, an
empty array is returned. If there is an error getting the embedding from the provider, an error is
thrown.
- Type
- Promise.<(Array.<string>|Array.<any>)>