A class that pools and runs requests to the Nomic embedding API. If you are dispatching dozens or more embedding requests in quick succession, this class handles pooling and backoff to ensure you get your results as quickly as possible.

For best results, do not await your embedding results until they are needed.

For example, if you are embedding 1000 lines of text, you can do the following:

GOOD -- Nomic will break down your big request into multiple medium-sized ones.

const documents = ["Once upon a time", "there was a girl named Goldilocks", …, "and they all lived happily ever after"]
const embedder = new Embedder(myApiKey)
const embeddings = await embedder.embed(documents)

GOOD -- Nomic will combine your small requests into several medium-size ones.

const documents = ["Once upon a time", "there was a girl named Goldilocks", …, "and they all lived happily ever after"]
const embedder = new Embedder(myApiKey)
const promises = []
for (let document of documents) {
promises.push(embedder.embed(document))
}
const embeddings = await Promise.all(promises)

BAD -- You will generate many small, inefficient requests.

 * const documents = ["Once upon a time", "there was a girl named Goldilocks", …, "and they all lived happily ever after"]
const embedder = new Embedder(myApiKey)
const embeddings = []
for (let document of documents) {
const embedding = await embedder.embed(document); // <- premature await.
embeddings.push(embedding);
}

Hierarchy

  • BaseAtlasClass<{}>
    • Embedder

Constructors

Properties

_attr: undefined | {}

Type declaration

    attributePromise: undefined | Promise<{}>
    backoff: null | number = null
    embedQueue: [string, ((embedding) => void), ((error) => void)][] = []
    epitaph?: Error
    model: EmbeddingModel
    nextScheduledFlush: unknown = null
    taskType: TaskType
    tokensUsed: number = 0
    viewer: AtlasViewer

    Accessors

    • get attr(): undefined | AttributesType
    • returns the object's information; this may be undefined

      Returns undefined | AttributesType

    Methods

    • Parameters

      • values: string[]

      Returns Promise<NomicEmbedResponse>

    • Parameters

      • endpoint: string
      • method: "GET" | "POST"
      • payload: Payload = null
      • headers: null | Record<string, string> = null

      Returns Promise<null | string | any[] | Record<string, any> | Uint8Array | Table<any>>

    • Parameters

      • value: string

      Returns Promise<Embedding>

    • Parameters

      • value: string[]

      Returns Promise<Embedding[]>

    • Fetches basic information about the object. By default, this caches the call; if you want to bust the cache, pass true as the first argument. This immediately.

      Parameters

      • bustCache: boolean = false

        Whether to refetch the relevant information

      Returns Promise<{}>

      A promise that resolves to the organization info.

    • Loads the information associated with the class, removing any existing caches.

      Returns Promise<LoadedObject<Embedder, {}>>

      a LoadedObject instance of the class that is guaranteed to have its attr slot populated with appropriate information.

      Example

      const loadedProject = await (new AtlasProject(projectId)).withLoadedAttributes()

      // OR, in cases where we want to do stuff immediately with the project and ensure
      // that later calls there don't double-fetch information.

      const project = new AtlasProject(projectId)

      // do stuff right away.
      const projection = new AtlasProjection(projectionId, {project: project})
      const loadedProjection = await projection.withLoadedAttributes()
      // do stuff with loadedProjection