Class that extends the Embeddings class and provides methods for generating embeddings using the Universal Sentence Encoder model from TensorFlow.js.

Example

const embeddings = new TensorFlowEmbeddings();
const store = new MemoryVectorStore(embeddings);

const documents = [
"A document",
"Some other piece of text",
"One more",
"And another",
];

await store.addDocuments(
documents.map((pageContent) => new Document({ pageContent }))
);

Hierarchy (view full)

Constructors

Methods

  • Method that takes an array of documents as input and returns a promise that resolves to a 2D array of embeddings for each document. It calls the _embed method with the documents as the input and processes the result to return the embeddings.

    Parameters

    • documents: string[]

      Array of documents to generate embeddings for.

    Returns Promise<number[][]>

    Promise that resolves to a 2D array of embeddings for each input document.

  • Method that takes a document as input and returns a promise that resolves to an embedding for the document. It calls the _embed method with the document as the input and processes the result to return a single embedding.

    Parameters

    • document: string

      Document to generate an embedding for.

    Returns Promise<number[]>

    Promise that resolves to an embedding for the input document.

Generated using TypeDoc