Socket
Socket
Sign inDemoInstall

chromadb

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chromadb - npm Package Compare versions

Comparing version 1.5.5 to 1.5.6

5

dist/main/ChromaClient.d.ts
import { IEmbeddingFunction } from './embeddings/IEmbeddingFunction';
import { Api } from "./generated";
import { Collection } from './Collection';

@@ -30,3 +29,3 @@ import { CollectionMetadata, CollectionType } from './types';

*
* @returns {Promise<Api.Reset200Response>} A promise that resolves when the reset operation is complete.
* @returns {Promise<boolean>} A promise that resolves when the reset operation is complete.
* @throws {Error} If there is an issue resetting the state.

@@ -39,3 +38,3 @@ *

*/
reset(): Promise<Api.Reset200Response>;
reset(): Promise<boolean>;
/**

@@ -42,0 +41,0 @@ * Returns the version of the Chroma API.

2

dist/main/ChromaClient.js

@@ -33,3 +33,3 @@ "use strict";

*
* @returns {Promise<Api.Reset200Response>} A promise that resolves when the reset operation is complete.
* @returns {Promise<boolean>} A promise that resolves when the reset operation is complete.
* @throws {Error} If there is an issue resetting the state.

@@ -36,0 +36,0 @@ *

import { IEmbeddingFunction } from "./IEmbeddingFunction";
/**
* WebAIEmbeddingFunction is a function that uses the Web AI package to generate embeddings.
* @remarks
* This embedding function can be used in both NodeJS and browser environments.
* Browser version of Web AI (@visheratin/web-ai) is an ESM module.
* NodeJS version of Web AI (@visheratin/web-ai-node) is a CommonJS module.
*/
export declare class WebAIEmbeddingFunction implements IEmbeddingFunction {
private model;
private proxy?;
private initPromise;
private modality;
/**
* WebAIEmbeddingFunction constructor.
* @param modality - the modality of the embedding function, either "text" or "image".
* @param modality - the modality of the embedding function, either "text", "image", or "multimodal".
* @param node - whether the embedding function is being used in a NodeJS environment.
* @param proxy - whether to use web worker to avoid blocking the main thread. Works only in browser.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files. Has to be specified when running in NodeJS.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files.
* @param modelID - the ID of the model to use, if not specified, the default model will be used.
*/
constructor(modality: "text" | "image", node: boolean, proxy?: boolean, wasmPath?: string, modelID?: string);
constructor(modality: "text" | "image" | "multimodal", node: boolean, proxy?: boolean, wasmPath?: string, modelID?: string);
/**

@@ -21,3 +30,5 @@ * Generates embeddings for the given values.

generate(values: string[]): Promise<number[][]>;
private initNode;
private initBrowser;
}
//# sourceMappingURL=WebAIEmbeddingFunction.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebAIEmbeddingFunction = void 0;
let webAI;
/**
* WebAIEmbeddingFunction is a function that uses the Web AI package to generate embeddings.
* @remarks
* This embedding function can be used in both NodeJS and browser environments.
* Browser version of Web AI (@visheratin/web-ai) is an ESM module.
* NodeJS version of Web AI (@visheratin/web-ai-node) is a CommonJS module.
*/
class WebAIEmbeddingFunction {
/**
* WebAIEmbeddingFunction constructor.
* @param modality - the modality of the embedding function, either "text" or "image".
* @param modality - the modality of the embedding function, either "text", "image", or "multimodal".
* @param node - whether the embedding function is being used in a NodeJS environment.
* @param proxy - whether to use web worker to avoid blocking the main thread. Works only in browser.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files. Has to be specified when running in NodeJS.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files.
* @param modelID - the ID of the model to use, if not specified, the default model will be used.
*/
constructor(modality, node, proxy, wasmPath, modelID) {
this.initPromise = null;
this.model = null;
this.modality = modality;
if (node) {
this.proxy = proxy ? proxy : false;
try {
webAI = require("@visheratin/web-ai-node");
}
catch (e) {
console.log(e);
throw new Error("Please install the @visheratin/web-ai-node package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai-node`");
}
this.initNode(modality, proxy, modelID);
}
else {
this.proxy = proxy ? proxy : true;
try {
webAI = require("@visheratin/web-ai");
}
catch (e) {
console.log(e);
throw new Error("Please install the @visheratin/web-ai package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai`");
}
this.initPromise = this.initBrowser(modality, proxy, wasmPath, modelID);
}
if (wasmPath) {
webAI.SessionParams.wasmRoot = wasmPath;
}
switch (modality) {
case "text": {
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAI.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAI.TextFeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find text model with id ${modelID} in the WebAI package`);
}
case "image": {
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAI.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAI.ImageFeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find image model with id ${modelID} in the WebAI package`);
}
}
}

@@ -76,7 +61,29 @@ /**

async generate(values) {
if (this.initPromise) {
await this.initPromise;
}
if (!this.model.initialized) {
await this.model.init(this.proxy);
}
const output = await this.model.process(values);
const embeddings = output.result;
let embeddings = [];
if (this.modality === "text" || this.modality === "image") {
const output = await this.model.process(values);
embeddings = output.result;
}
else {
const urlValues = [];
const textValues = [];
for (const value of values) {
try {
new URL(value);
urlValues.push(value);
}
catch (_a) {
textValues.push(value);
}
}
const urlOutput = await this.model.embedImages(urlValues);
const textOutput = await this.model.embedTexts(textValues);
embeddings = urlOutput.concat(textOutput);
}
if (embeddings.length > 0 && Array.isArray(embeddings[0])) {

@@ -89,4 +96,125 @@ return embeddings;

}
initNode(modality, proxy, modelID) {
this.proxy = proxy ? proxy : false;
try {
const webAI = require("@visheratin/web-ai-node");
webAI.SessionParams.executionProviders = ["cpu"];
switch (modality) {
case "text": {
const webAIText = require("@visheratin/web-ai-node/text");
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAIText.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAIText.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find text model with id ${modelID} in the Web AI package`);
}
case "image": {
const webAIImage = require("@visheratin/web-ai-node/image");
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find image model with id ${modelID} in the Web AI package`);
}
case "multimodal": {
const webAIMultimodal = require("@visheratin/web-ai-node/multimodal");
let id = "clip-base-quant"; //default multimodal model
if (modelID) {
id = modelID;
}
const multimodalModels = webAIMultimodal.ListMultimodalModels();
for (const modelMetadata of multimodalModels) {
if (modelMetadata.id === id) {
this.model = new webAIMultimodal.ZeroShotClassificationModel(modelMetadata);
return;
}
}
throw new Error(`Could not find multimodal model with id ${modelID} in the Web AI package`);
}
}
}
catch (e) {
console.error(e);
throw new Error("Please install the @visheratin/web-ai-node package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai-node`");
}
}
async initBrowser(modality, proxy, modelID, wasmPath) {
this.proxy = proxy ? proxy : true;
try {
// @ts-ignore
const webAI = await Promise.resolve().then(() => __importStar(require("@visheratin/web-ai")));
if (wasmPath) {
webAI.SessionParams.wasmRoot = wasmPath;
}
switch (modality) {
case "text": {
// @ts-ignore
const webAIText = await Promise.resolve().then(() => __importStar(require("@visheratin/web-ai/text")));
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAIText.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAIText.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find text model with id ${modelID} in the Web AI package`);
}
case "image": {
// @ts-ignore
const webAIImage = await Promise.resolve().then(() => __importStar(require("@visheratin/web-ai/image")));
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find image model with id ${modelID} in the Web AI package`);
}
case "multimodal": {
// @ts-ignore
const webAIImage = await Promise.resolve().then(() => __importStar(require("@visheratin/web-ai/multimodal")));
let id = "clip-base-quant"; //default multimodal model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListMultimodalModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.ZeroShotClassificationModel(modelMetadata);
return;
}
}
throw new Error(`Could not find multimodal model with id ${modelID} in the Web AI package`);
}
}
}
catch (e) {
throw new Error("Please install the @visheratin/web-ai package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai`");
}
}
}
exports.WebAIEmbeddingFunction = WebAIEmbeddingFunction;
//# sourceMappingURL=WebAIEmbeddingFunction.js.map

@@ -60,9 +60,2 @@ /**

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options?: RequestInit): FetchArgs;
/**
* @summary Delete Collection

@@ -102,9 +95,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options?: RequestInit): FetchArgs;
/**
* @summary Reset

@@ -196,9 +182,2 @@ * @param {RequestInit} [options] Override http request option.

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.CreateIndex200Response>;
/**
* @summary Delete Collection

@@ -230,3 +209,5 @@ * @param {string} collectionName

*/
heartbeat(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Heartbeat200Response>;
heartbeat(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<{
[name: string]: number;
}>;
/**

@@ -239,9 +220,2 @@ * @summary List Collections

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.RawSql200Response>;
/**
* @summary Reset

@@ -251,3 +225,3 @@ * @param {RequestInit} [options] Override http request option.

*/
reset(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Reset200Response>;
reset(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<boolean>;
/**

@@ -258,3 +232,5 @@ * @summary Root

*/
root(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Root200Response>;
root(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<{
[name: string]: number;
}>;
/**

@@ -289,3 +265,3 @@ * @summary Update

*/
version(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Version200Response>;
version(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<string>;
};

@@ -343,9 +319,2 @@ /**

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options?: RequestInit): Promise<Api.CreateIndex200Response>;
/**
* @summary Delete Collection

@@ -377,3 +346,5 @@ * @param {string} collectionName

*/
heartbeat(options?: RequestInit): Promise<Api.Heartbeat200Response>;
heartbeat(options?: RequestInit): Promise<{
[name: string]: number;
}>;
/**

@@ -386,9 +357,2 @@ * @summary List Collections

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options?: RequestInit): Promise<Api.RawSql200Response>;
/**
* @summary Reset

@@ -398,3 +362,3 @@ * @param {RequestInit} [options] Override http request option.

*/
reset(options?: RequestInit): Promise<Api.Reset200Response>;
reset(options?: RequestInit): Promise<boolean>;
/**

@@ -405,3 +369,5 @@ * @summary Root

*/
root(options?: RequestInit): Promise<Api.Root200Response>;
root(options?: RequestInit): Promise<{
[name: string]: number;
}>;
/**

@@ -436,4 +402,4 @@ * @summary Update

*/
version(options?: RequestInit): Promise<Api.Version200Response>;
version(options?: RequestInit): Promise<string>;
}
//# sourceMappingURL=api.d.ts.map

@@ -205,32 +205,2 @@ "use strict";

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName, options = {}) {
// verify required parameter 'collectionName' is not null or undefined
if (collectionName === null || collectionName === undefined) {
throw new runtime_1.RequiredError('collectionName', 'Required parameter collectionName was null or undefined when calling createIndex.');
}
let localVarPath = `/api/v1/collections/{collection_name}/create_index`
.replace('{collection_name}', encodeURIComponent(String(collectionName)));
const localVarPathQueryStart = localVarPath.indexOf("?");
const localVarRequestOptions = Object.assign({ method: 'POST' }, options);
const localVarHeaderParameter = options.headers ? new Headers(options.headers) : new Headers();
const localVarQueryParameter = new URLSearchParams(localVarPathQueryStart !== -1 ? localVarPath.substring(localVarPathQueryStart + 1) : "");
if (localVarPathQueryStart !== -1) {
localVarPath = localVarPath.substring(0, localVarPathQueryStart);
}
localVarRequestOptions.headers = localVarHeaderParameter;
const localVarQueryParameterString = localVarQueryParameter.toString();
if (localVarQueryParameterString) {
localVarPath += "?" + localVarQueryParameterString;
}
return {
url: localVarPath,
options: localVarRequestOptions,
};
},
/**
* @summary Delete Collection

@@ -383,35 +353,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request, options = {}) {
// verify required parameter 'request' is not null or undefined
if (request === null || request === undefined) {
throw new runtime_1.RequiredError('request', 'Required parameter request was null or undefined when calling rawSql.');
}
let localVarPath = `/api/v1/raw_sql`;
const localVarPathQueryStart = localVarPath.indexOf("?");
const localVarRequestOptions = Object.assign({ method: 'POST' }, options);
const localVarHeaderParameter = options.headers ? new Headers(options.headers) : new Headers();
const localVarQueryParameter = new URLSearchParams(localVarPathQueryStart !== -1 ? localVarPath.substring(localVarPathQueryStart + 1) : "");
if (localVarPathQueryStart !== -1) {
localVarPath = localVarPath.substring(0, localVarPathQueryStart);
}
localVarHeaderParameter.set('Content-Type', 'application/json');
localVarRequestOptions.headers = localVarHeaderParameter;
if (request !== undefined) {
localVarRequestOptions.body = JSON.stringify(request || {});
}
const localVarQueryParameterString = localVarQueryParameter.toString();
if (localVarQueryParameterString) {
localVarPath += "?" + localVarQueryParameterString;
}
return {
url: localVarPath,
options: localVarRequestOptions,
};
},
/**
* @summary Reset

@@ -758,30 +695,2 @@ * @param {RequestInit} [options] Override http request option.

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName, options) {
const localVarFetchArgs = (0, exports.ApiApiFetchParamCreator)(configuration).createIndex(collectionName, options);
return (fetch = runtime_1.defaultFetch, basePath = runtime_1.BASE_PATH) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
const contentType = response.headers.get('Content-Type');
const mimeType = contentType ? contentType.replace(/;.*/, '') : undefined;
if (response.status === 200) {
if (mimeType === 'application/json') {
return response.json();
}
throw response;
}
if (response.status === 422) {
if (mimeType === 'application/json') {
throw response;
}
throw response;
}
throw response;
});
};
},
/**
* @summary Delete Collection

@@ -914,30 +823,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request, options) {
const localVarFetchArgs = (0, exports.ApiApiFetchParamCreator)(configuration).rawSql(request, options);
return (fetch = runtime_1.defaultFetch, basePath = runtime_1.BASE_PATH) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
const contentType = response.headers.get('Content-Type');
const mimeType = contentType ? contentType.replace(/;.*/, '') : undefined;
if (response.status === 200) {
if (mimeType === 'application/json') {
return response.json();
}
throw response;
}
if (response.status === 422) {
if (mimeType === 'application/json') {
throw response;
}
throw response;
}
throw response;
});
};
},
/**
* @summary Reset

@@ -1159,11 +1040,2 @@ * @param {RequestInit} [options] Override http request option.

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName, options) {
return (0, exports.ApiApiFp)(this.configuration).createIndex(collectionName, options)(this.fetch, this.basePath);
}
/**
* @summary Delete Collection

@@ -1213,11 +1085,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request, options) {
return (0, exports.ApiApiFp)(this.configuration).rawSql(request, options)(this.fetch, this.basePath);
}
/**
* @summary Reset

@@ -1224,0 +1087,0 @@ * @param {RequestInit} [options] Override http request option.

@@ -20,3 +20,2 @@ /**

ids: string[];
'increment_index'?: boolean;
}

@@ -54,4 +53,2 @@ /**

}
interface CreateIndex200Response {
}
interface DeleteCollection200Response {

@@ -124,4 +121,2 @@ }

}
interface Heartbeat200Response {
}
interface HTTPValidationError {

@@ -174,11 +169,2 @@ detail?: Api.ValidationError[];

}
interface RawSql {
'raw_sql': string;
}
interface RawSql200Response {
}
interface Reset200Response {
}
interface Root200Response {
}
interface Update200Response {

@@ -205,3 +191,2 @@ }

ids: string[];
'increment_index'?: boolean;
}

@@ -225,5 +210,3 @@ /**

}
interface Version200Response {
}
}
//# sourceMappingURL=models.d.ts.map
import { IEmbeddingFunction } from './embeddings/IEmbeddingFunction';
import { Api } from "./generated";
import { Collection } from './Collection';

@@ -30,3 +29,3 @@ import { CollectionMetadata, CollectionType } from './types';

*
* @returns {Promise<Api.Reset200Response>} A promise that resolves when the reset operation is complete.
* @returns {Promise<boolean>} A promise that resolves when the reset operation is complete.
* @throws {Error} If there is an issue resetting the state.

@@ -39,3 +38,3 @@ *

*/
reset(): Promise<Api.Reset200Response>;
reset(): Promise<boolean>;
/**

@@ -42,0 +41,0 @@ * Returns the version of the Chroma API.

@@ -30,3 +30,3 @@ import { Configuration, ApiApi as DefaultApi } from "./generated";

*
* @returns {Promise<Api.Reset200Response>} A promise that resolves when the reset operation is complete.
* @returns {Promise<boolean>} A promise that resolves when the reset operation is complete.
* @throws {Error} If there is an issue resetting the state.

@@ -33,0 +33,0 @@ *

import { IEmbeddingFunction } from "./IEmbeddingFunction";
/**
* WebAIEmbeddingFunction is a function that uses the Web AI package to generate embeddings.
* @remarks
* This embedding function can be used in both NodeJS and browser environments.
* Browser version of Web AI (@visheratin/web-ai) is an ESM module.
* NodeJS version of Web AI (@visheratin/web-ai-node) is a CommonJS module.
*/
export declare class WebAIEmbeddingFunction implements IEmbeddingFunction {
private model;
private proxy?;
private initPromise;
private modality;
/**
* WebAIEmbeddingFunction constructor.
* @param modality - the modality of the embedding function, either "text" or "image".
* @param modality - the modality of the embedding function, either "text", "image", or "multimodal".
* @param node - whether the embedding function is being used in a NodeJS environment.
* @param proxy - whether to use web worker to avoid blocking the main thread. Works only in browser.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files. Has to be specified when running in NodeJS.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files.
* @param modelID - the ID of the model to use, if not specified, the default model will be used.
*/
constructor(modality: "text" | "image", node: boolean, proxy?: boolean, wasmPath?: string, modelID?: string);
constructor(modality: "text" | "image" | "multimodal", node: boolean, proxy?: boolean, wasmPath?: string, modelID?: string);
/**

@@ -21,3 +30,5 @@ * Generates embeddings for the given values.

generate(values: string[]): Promise<number[][]>;
private initNode;
private initBrowser;
}
//# sourceMappingURL=WebAIEmbeddingFunction.d.ts.map

@@ -1,65 +0,27 @@

let webAI;
/**
* WebAIEmbeddingFunction is a function that uses the Web AI package to generate embeddings.
* @remarks
* This embedding function can be used in both NodeJS and browser environments.
* Browser version of Web AI (@visheratin/web-ai) is an ESM module.
* NodeJS version of Web AI (@visheratin/web-ai-node) is a CommonJS module.
*/
export class WebAIEmbeddingFunction {
/**
* WebAIEmbeddingFunction constructor.
* @param modality - the modality of the embedding function, either "text" or "image".
* @param modality - the modality of the embedding function, either "text", "image", or "multimodal".
* @param node - whether the embedding function is being used in a NodeJS environment.
* @param proxy - whether to use web worker to avoid blocking the main thread. Works only in browser.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files. Has to be specified when running in NodeJS.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files.
* @param modelID - the ID of the model to use, if not specified, the default model will be used.
*/
constructor(modality, node, proxy, wasmPath, modelID) {
this.initPromise = null;
this.model = null;
this.modality = modality;
if (node) {
this.proxy = proxy ? proxy : false;
try {
webAI = require("@visheratin/web-ai-node");
}
catch (e) {
console.log(e);
throw new Error("Please install the @visheratin/web-ai-node package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai-node`");
}
this.initNode(modality, proxy, modelID);
}
else {
this.proxy = proxy ? proxy : true;
try {
webAI = require("@visheratin/web-ai");
}
catch (e) {
console.log(e);
throw new Error("Please install the @visheratin/web-ai package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai`");
}
this.initPromise = this.initBrowser(modality, proxy, wasmPath, modelID);
}
if (wasmPath) {
webAI.SessionParams.wasmRoot = wasmPath;
}
switch (modality) {
case "text": {
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAI.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAI.TextFeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find text model with id ${modelID} in the WebAI package`);
}
case "image": {
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAI.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAI.ImageFeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find image model with id ${modelID} in the WebAI package`);
}
}
}

@@ -73,7 +35,29 @@ /**

async generate(values) {
if (this.initPromise) {
await this.initPromise;
}
if (!this.model.initialized) {
await this.model.init(this.proxy);
}
const output = await this.model.process(values);
const embeddings = output.result;
let embeddings = [];
if (this.modality === "text" || this.modality === "image") {
const output = await this.model.process(values);
embeddings = output.result;
}
else {
const urlValues = [];
const textValues = [];
for (const value of values) {
try {
new URL(value);
urlValues.push(value);
}
catch (_a) {
textValues.push(value);
}
}
const urlOutput = await this.model.embedImages(urlValues);
const textOutput = await this.model.embedTexts(textValues);
embeddings = urlOutput.concat(textOutput);
}
if (embeddings.length > 0 && Array.isArray(embeddings[0])) {

@@ -86,3 +70,124 @@ return embeddings;

}
initNode(modality, proxy, modelID) {
this.proxy = proxy ? proxy : false;
try {
const webAI = require("@visheratin/web-ai-node");
webAI.SessionParams.executionProviders = ["cpu"];
switch (modality) {
case "text": {
const webAIText = require("@visheratin/web-ai-node/text");
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAIText.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAIText.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find text model with id ${modelID} in the Web AI package`);
}
case "image": {
const webAIImage = require("@visheratin/web-ai-node/image");
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find image model with id ${modelID} in the Web AI package`);
}
case "multimodal": {
const webAIMultimodal = require("@visheratin/web-ai-node/multimodal");
let id = "clip-base-quant"; //default multimodal model
if (modelID) {
id = modelID;
}
const multimodalModels = webAIMultimodal.ListMultimodalModels();
for (const modelMetadata of multimodalModels) {
if (modelMetadata.id === id) {
this.model = new webAIMultimodal.ZeroShotClassificationModel(modelMetadata);
return;
}
}
throw new Error(`Could not find multimodal model with id ${modelID} in the Web AI package`);
}
}
}
catch (e) {
console.error(e);
throw new Error("Please install the @visheratin/web-ai-node package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai-node`");
}
}
async initBrowser(modality, proxy, modelID, wasmPath) {
this.proxy = proxy ? proxy : true;
try {
// @ts-ignore
const webAI = await import("@visheratin/web-ai");
if (wasmPath) {
webAI.SessionParams.wasmRoot = wasmPath;
}
switch (modality) {
case "text": {
// @ts-ignore
const webAIText = await import("@visheratin/web-ai/text");
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAIText.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAIText.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find text model with id ${modelID} in the Web AI package`);
}
case "image": {
// @ts-ignore
const webAIImage = await import("@visheratin/web-ai/image");
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(`Could not find image model with id ${modelID} in the Web AI package`);
}
case "multimodal": {
// @ts-ignore
const webAIImage = await import("@visheratin/web-ai/multimodal");
let id = "clip-base-quant"; //default multimodal model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListMultimodalModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.ZeroShotClassificationModel(modelMetadata);
return;
}
}
throw new Error(`Could not find multimodal model with id ${modelID} in the Web AI package`);
}
}
}
catch (e) {
throw new Error("Please install the @visheratin/web-ai package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai`");
}
}
}
//# sourceMappingURL=WebAIEmbeddingFunction.js.map

@@ -60,9 +60,2 @@ /**

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options?: RequestInit): FetchArgs;
/**
* @summary Delete Collection

@@ -102,9 +95,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options?: RequestInit): FetchArgs;
/**
* @summary Reset

@@ -196,9 +182,2 @@ * @param {RequestInit} [options] Override http request option.

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.CreateIndex200Response>;
/**
* @summary Delete Collection

@@ -230,3 +209,5 @@ * @param {string} collectionName

*/
heartbeat(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Heartbeat200Response>;
heartbeat(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<{
[name: string]: number;
}>;
/**

@@ -239,9 +220,2 @@ * @summary List Collections

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.RawSql200Response>;
/**
* @summary Reset

@@ -251,3 +225,3 @@ * @param {RequestInit} [options] Override http request option.

*/
reset(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Reset200Response>;
reset(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<boolean>;
/**

@@ -258,3 +232,5 @@ * @summary Root

*/
root(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Root200Response>;
root(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<{
[name: string]: number;
}>;
/**

@@ -289,3 +265,3 @@ * @summary Update

*/
version(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Version200Response>;
version(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<string>;
};

@@ -343,9 +319,2 @@ /**

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options?: RequestInit): Promise<Api.CreateIndex200Response>;
/**
* @summary Delete Collection

@@ -377,3 +346,5 @@ * @param {string} collectionName

*/
heartbeat(options?: RequestInit): Promise<Api.Heartbeat200Response>;
heartbeat(options?: RequestInit): Promise<{
[name: string]: number;
}>;
/**

@@ -386,9 +357,2 @@ * @summary List Collections

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options?: RequestInit): Promise<Api.RawSql200Response>;
/**
* @summary Reset

@@ -398,3 +362,3 @@ * @param {RequestInit} [options] Override http request option.

*/
reset(options?: RequestInit): Promise<Api.Reset200Response>;
reset(options?: RequestInit): Promise<boolean>;
/**

@@ -405,3 +369,5 @@ * @summary Root

*/
root(options?: RequestInit): Promise<Api.Root200Response>;
root(options?: RequestInit): Promise<{
[name: string]: number;
}>;
/**

@@ -436,4 +402,4 @@ * @summary Update

*/
version(options?: RequestInit): Promise<Api.Version200Response>;
version(options?: RequestInit): Promise<string>;
}
//# sourceMappingURL=api.d.ts.map

@@ -202,32 +202,2 @@ /* eslint-disable */

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName, options = {}) {
// verify required parameter 'collectionName' is not null or undefined
if (collectionName === null || collectionName === undefined) {
throw new RequiredError('collectionName', 'Required parameter collectionName was null or undefined when calling createIndex.');
}
let localVarPath = `/api/v1/collections/{collection_name}/create_index`
.replace('{collection_name}', encodeURIComponent(String(collectionName)));
const localVarPathQueryStart = localVarPath.indexOf("?");
const localVarRequestOptions = Object.assign({ method: 'POST' }, options);
const localVarHeaderParameter = options.headers ? new Headers(options.headers) : new Headers();
const localVarQueryParameter = new URLSearchParams(localVarPathQueryStart !== -1 ? localVarPath.substring(localVarPathQueryStart + 1) : "");
if (localVarPathQueryStart !== -1) {
localVarPath = localVarPath.substring(0, localVarPathQueryStart);
}
localVarRequestOptions.headers = localVarHeaderParameter;
const localVarQueryParameterString = localVarQueryParameter.toString();
if (localVarQueryParameterString) {
localVarPath += "?" + localVarQueryParameterString;
}
return {
url: localVarPath,
options: localVarRequestOptions,
};
},
/**
* @summary Delete Collection

@@ -380,35 +350,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request, options = {}) {
// verify required parameter 'request' is not null or undefined
if (request === null || request === undefined) {
throw new RequiredError('request', 'Required parameter request was null or undefined when calling rawSql.');
}
let localVarPath = `/api/v1/raw_sql`;
const localVarPathQueryStart = localVarPath.indexOf("?");
const localVarRequestOptions = Object.assign({ method: 'POST' }, options);
const localVarHeaderParameter = options.headers ? new Headers(options.headers) : new Headers();
const localVarQueryParameter = new URLSearchParams(localVarPathQueryStart !== -1 ? localVarPath.substring(localVarPathQueryStart + 1) : "");
if (localVarPathQueryStart !== -1) {
localVarPath = localVarPath.substring(0, localVarPathQueryStart);
}
localVarHeaderParameter.set('Content-Type', 'application/json');
localVarRequestOptions.headers = localVarHeaderParameter;
if (request !== undefined) {
localVarRequestOptions.body = JSON.stringify(request || {});
}
const localVarQueryParameterString = localVarQueryParameter.toString();
if (localVarQueryParameterString) {
localVarPath += "?" + localVarQueryParameterString;
}
return {
url: localVarPath,
options: localVarRequestOptions,
};
},
/**
* @summary Reset

@@ -754,30 +691,2 @@ * @param {RequestInit} [options] Override http request option.

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName, options) {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).createIndex(collectionName, options);
return (fetch = defaultFetch, basePath = BASE_PATH) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
const contentType = response.headers.get('Content-Type');
const mimeType = contentType ? contentType.replace(/;.*/, '') : undefined;
if (response.status === 200) {
if (mimeType === 'application/json') {
return response.json();
}
throw response;
}
if (response.status === 422) {
if (mimeType === 'application/json') {
throw response;
}
throw response;
}
throw response;
});
};
},
/**
* @summary Delete Collection

@@ -910,30 +819,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request, options) {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).rawSql(request, options);
return (fetch = defaultFetch, basePath = BASE_PATH) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
const contentType = response.headers.get('Content-Type');
const mimeType = contentType ? contentType.replace(/;.*/, '') : undefined;
if (response.status === 200) {
if (mimeType === 'application/json') {
return response.json();
}
throw response;
}
if (response.status === 422) {
if (mimeType === 'application/json') {
throw response;
}
throw response;
}
throw response;
});
};
},
/**
* @summary Reset

@@ -1153,11 +1034,2 @@ * @param {RequestInit} [options] Override http request option.

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName, options) {
return ApiApiFp(this.configuration).createIndex(collectionName, options)(this.fetch, this.basePath);
}
/**
* @summary Delete Collection

@@ -1207,11 +1079,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request, options) {
return ApiApiFp(this.configuration).rawSql(request, options)(this.fetch, this.basePath);
}
/**
* @summary Reset

@@ -1218,0 +1081,0 @@ * @param {RequestInit} [options] Override http request option.

@@ -20,3 +20,2 @@ /**

ids: string[];
'increment_index'?: boolean;
}

@@ -54,4 +53,2 @@ /**

}
interface CreateIndex200Response {
}
interface DeleteCollection200Response {

@@ -124,4 +121,2 @@ }

}
interface Heartbeat200Response {
}
interface HTTPValidationError {

@@ -174,11 +169,2 @@ detail?: Api.ValidationError[];

}
interface RawSql {
'raw_sql': string;
}
interface RawSql200Response {
}
interface Reset200Response {
}
interface Root200Response {
}
interface Update200Response {

@@ -205,3 +191,2 @@ }

ids: string[];
'increment_index'?: boolean;
}

@@ -225,5 +210,3 @@ /**

}
interface Version200Response {
}
}
//# sourceMappingURL=models.d.ts.map
{
"name": "chromadb",
"version": "1.5.5",
"version": "1.5.6",
"description": "A JavaScript interface for chroma",

@@ -46,2 +46,2 @@ "keywords": [],

}
}
}

@@ -22,10 +22,15 @@ ## chromadb

import { ChromaClient } from "chromadb";
const chroma = new ChromaClient("http://localhost:8000");
const collection = await chroma.createCollection("test-from-js");
const chroma = new ChromaClient({ path: "http://localhost:8000" });
const collection = await chroma.createCollection({ name: "test-from-js" });
for (let i = 0; i < 20; i++) {
await collection.add("test-id-" + i.toString(), [1, 2, 3, 4, 5], {
test: "test",
await collection.add({
ids: ["test-id-" + i.toString()],
embeddings, [1, 2, 3, 4, 5],
documents: ["test"],
});
}
const queryData = await collection.query([1, 2, 3, 4, 5], 5, { test: "test" });
const queryData = await collection.query({
queryEmbeddings: [1, 2, 3, 4, 5],
queryTexts: ["test"],
});
```

@@ -32,0 +37,0 @@

@@ -45,3 +45,3 @@ import { IEmbeddingFunction } from './embeddings/IEmbeddingFunction';

*
* @returns {Promise<Api.Reset200Response>} A promise that resolves when the reset operation is complete.
* @returns {Promise<boolean>} A promise that resolves when the reset operation is complete.
* @throws {Error} If there is an issue resetting the state.

@@ -54,3 +54,3 @@ *

*/
public async reset(): Promise<Api.Reset200Response> {
public async reset(): Promise<boolean> {
return await this.api.reset(this.api.options);

@@ -57,0 +57,0 @@ }

import { IEmbeddingFunction } from "./IEmbeddingFunction";
let webAI: any;
/**
* WebAIEmbeddingFunction is a function that uses the Web AI package to generate embeddings.
* @remarks
* This embedding function can be used in both NodeJS and browser environments.
* Browser version of Web AI (@visheratin/web-ai) is an ESM module.
* NodeJS version of Web AI (@visheratin/web-ai-node) is a CommonJS module.
*/
export class WebAIEmbeddingFunction implements IEmbeddingFunction {
private model;
private model: any;
private proxy?: boolean;
private initPromise: Promise<any> | null;
private modality: "text" | "image" | "multimodal";
/**
* WebAIEmbeddingFunction constructor.
* @param modality - the modality of the embedding function, either "text" or "image".
* @param modality - the modality of the embedding function, either "text", "image", or "multimodal".
* @param node - whether the embedding function is being used in a NodeJS environment.
* @param proxy - whether to use web worker to avoid blocking the main thread. Works only in browser.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files. Has to be specified when running in NodeJS.
* @param wasmPath - the path/URL to the directory with ONNX runtime WebAssembly files.
* @param modelID - the ID of the model to use, if not specified, the default model will be used.
*/
constructor(
modality: "text" | "image",
modality: "text" | "image" | "multimodal",
node: boolean,

@@ -23,60 +31,10 @@ proxy?: boolean,

) {
this.initPromise = null;
this.model = null;
this.modality = modality;
if (node) {
this.proxy = proxy ? proxy : false;
try {
webAI = require("@visheratin/web-ai-node");
} catch (e) {
console.log(e);
throw new Error(
"Please install the @visheratin/web-ai-node package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai-node`"
);
}
this.initNode(modality, proxy, modelID);
} else {
this.proxy = proxy ? proxy : true;
try {
webAI = require("@visheratin/web-ai");
} catch (e) {
console.log(e);
throw new Error(
"Please install the @visheratin/web-ai package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai`"
);
}
this.initPromise = this.initBrowser(modality, proxy, wasmPath, modelID);
}
if (wasmPath) {
webAI.SessionParams.wasmRoot = wasmPath;
}
switch (modality) {
case "text": {
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAI.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAI.TextFeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(
`Could not find text model with id ${modelID} in the WebAI package`
);
}
case "image": {
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAI.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAI.ImageFeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(
`Could not find image model with id ${modelID} in the WebAI package`
);
}
}
}

@@ -91,7 +49,27 @@

public async generate(values: string[]): Promise<number[][]> {
if (this.initPromise) {
await this.initPromise;
}
if (!this.model.initialized) {
await this.model.init(this.proxy);
}
const output = await this.model.process(values);
const embeddings = output.result;
let embeddings = [];
if (this.modality === "text" || this.modality === "image") {
const output = await this.model.process(values);
embeddings = output.result;
} else {
const urlValues = [];
const textValues = [];
for (const value of values) {
try {
new URL(value);
urlValues.push(value);
} catch {
textValues.push(value);
}
}
const urlOutput = await this.model.embedImages(urlValues);
const textOutput = await this.model.embedTexts(textValues);
embeddings = urlOutput.concat(textOutput);
}
if (embeddings.length > 0 && Array.isArray(embeddings[0])) {

@@ -103,2 +81,152 @@ return embeddings;

}
private initNode(
modality: "text" | "image" | "multimodal",
proxy?: boolean,
modelID?: string
): void {
this.proxy = proxy ? proxy : false;
try {
const webAI = require("@visheratin/web-ai-node");
webAI.SessionParams.executionProviders = ["cpu"];
switch (modality) {
case "text": {
const webAIText = require("@visheratin/web-ai-node/text");
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAIText.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAIText.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(
`Could not find text model with id ${modelID} in the Web AI package`
);
}
case "image": {
const webAIImage = require("@visheratin/web-ai-node/image");
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(
`Could not find image model with id ${modelID} in the Web AI package`
);
}
case "multimodal": {
const webAIMultimodal = require("@visheratin/web-ai-node/multimodal");
let id = "clip-base-quant"; //default multimodal model
if (modelID) {
id = modelID;
}
const multimodalModels = webAIMultimodal.ListMultimodalModels();
for (const modelMetadata of multimodalModels) {
if (modelMetadata.id === id) {
this.model = new webAIMultimodal.ZeroShotClassificationModel(
modelMetadata
);
return;
}
}
throw new Error(
`Could not find multimodal model with id ${modelID} in the Web AI package`
);
}
}
} catch (e) {
console.error(e);
throw new Error(
"Please install the @visheratin/web-ai-node package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai-node`"
);
}
}
private async initBrowser(
modality: "text" | "image" | "multimodal",
proxy?: boolean,
modelID?: string,
wasmPath?: string
) {
this.proxy = proxy ? proxy : true;
try {
// @ts-ignore
const webAI = await import("@visheratin/web-ai");
if (wasmPath) {
webAI.SessionParams.wasmRoot = wasmPath;
}
switch (modality) {
case "text": {
// @ts-ignore
const webAIText = await import("@visheratin/web-ai/text");
let id = "mini-lm-v2-quant"; //default text model
if (modelID) {
id = modelID;
}
const models = webAIText.ListTextModels();
for (const modelMetadata of models) {
if (modelMetadata.id === id) {
this.model = new webAIText.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(
`Could not find text model with id ${modelID} in the Web AI package`
);
}
case "image": {
// @ts-ignore
const webAIImage = await import("@visheratin/web-ai/image");
let id = "efficientformer-l1-feature-quant"; //default image model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListImageModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.FeatureExtractionModel(modelMetadata);
return;
}
}
throw new Error(
`Could not find image model with id ${modelID} in the Web AI package`
);
}
case "multimodal": {
// @ts-ignore
const webAIImage = await import("@visheratin/web-ai/multimodal");
let id = "clip-base-quant"; //default multimodal model
if (modelID) {
id = modelID;
}
const imageModels = webAIImage.ListMultimodalModels();
for (const modelMetadata of imageModels) {
if (modelMetadata.id === id) {
this.model = new webAIImage.ZeroShotClassificationModel(
modelMetadata
);
return;
}
}
throw new Error(
`Could not find multimodal model with id ${modelID} in the Web AI package`
);
}
}
} catch (e) {
throw new Error(
"Please install the @visheratin/web-ai package to use the WebAIEmbeddingFunction, `npm install -S @visheratin/web-ai`"
);
}
}
}

@@ -226,34 +226,2 @@ /* eslint-disable */

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options: RequestInit = {}): FetchArgs {
// verify required parameter 'collectionName' is not null or undefined
if (collectionName === null || collectionName === undefined) {
throw new RequiredError('collectionName', 'Required parameter collectionName was null or undefined when calling createIndex.');
}
let localVarPath = `/api/v1/collections/{collection_name}/create_index`
.replace('{collection_name}', encodeURIComponent(String(collectionName)));
const localVarPathQueryStart = localVarPath.indexOf("?");
const localVarRequestOptions: RequestInit = Object.assign({ method: 'POST' }, options);
const localVarHeaderParameter: Headers = options.headers ? new Headers(options.headers) : new Headers();
const localVarQueryParameter = new URLSearchParams(localVarPathQueryStart !== -1 ? localVarPath.substring(localVarPathQueryStart + 1) : "");
if (localVarPathQueryStart !== -1) {
localVarPath = localVarPath.substring(0, localVarPathQueryStart);
}
localVarRequestOptions.headers = localVarHeaderParameter;
const localVarQueryParameterString = localVarQueryParameter.toString();
if (localVarQueryParameterString) {
localVarPath += "?" + localVarQueryParameterString;
}
return {
url: localVarPath,
options: localVarRequestOptions,
};
},
/**
* @summary Delete Collection

@@ -418,39 +386,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options: RequestInit = {}): FetchArgs {
// verify required parameter 'request' is not null or undefined
if (request === null || request === undefined) {
throw new RequiredError('request', 'Required parameter request was null or undefined when calling rawSql.');
}
let localVarPath = `/api/v1/raw_sql`;
const localVarPathQueryStart = localVarPath.indexOf("?");
const localVarRequestOptions: RequestInit = Object.assign({ method: 'POST' }, options);
const localVarHeaderParameter: Headers = options.headers ? new Headers(options.headers) : new Headers();
const localVarQueryParameter = new URLSearchParams(localVarPathQueryStart !== -1 ? localVarPath.substring(localVarPathQueryStart + 1) : "");
if (localVarPathQueryStart !== -1) {
localVarPath = localVarPath.substring(0, localVarPathQueryStart);
}
localVarHeaderParameter.set('Content-Type', 'application/json');
localVarRequestOptions.headers = localVarHeaderParameter;
if (request !== undefined) {
localVarRequestOptions.body = JSON.stringify(request || {});
}
const localVarQueryParameterString = localVarQueryParameter.toString();
if (localVarQueryParameterString) {
localVarPath += "?" + localVarQueryParameterString;
}
return {
url: localVarPath,
options: localVarRequestOptions,
};
},
/**
* @summary Reset

@@ -820,31 +751,2 @@ * @param {RequestInit} [options] Override http request option.

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
createIndex(collectionName: string, options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.CreateIndex200Response> {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).createIndex(collectionName, options);
return (fetch: FetchAPI = defaultFetch, basePath: string = BASE_PATH) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
const contentType = response.headers.get('Content-Type');
const mimeType = contentType ? contentType.replace(/;.*/, '') : undefined;
if (response.status === 200) {
if (mimeType === 'application/json') {
return response.json() as any;
}
throw response;
}
if (response.status === 422) {
if (mimeType === 'application/json') {
throw response;
}
throw response;
}
throw response;
});
};
},
/**
* @summary Delete Collection

@@ -942,3 +844,3 @@ * @param {string} collectionName

*/
heartbeat(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Heartbeat200Response> {
heartbeat(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<{ [name: string]: number }> {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).heartbeat(options);

@@ -983,31 +885,2 @@ return (fetch: FetchAPI = defaultFetch, basePath: string = BASE_PATH) => {

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
rawSql(request: Api.RawSql, options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.RawSql200Response> {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).rawSql(request, options);
return (fetch: FetchAPI = defaultFetch, basePath: string = BASE_PATH) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
const contentType = response.headers.get('Content-Type');
const mimeType = contentType ? contentType.replace(/;.*/, '') : undefined;
if (response.status === 200) {
if (mimeType === 'application/json') {
return response.json() as any;
}
throw response;
}
if (response.status === 422) {
if (mimeType === 'application/json') {
throw response;
}
throw response;
}
throw response;
});
};
},
/**
* @summary Reset

@@ -1017,3 +890,3 @@ * @param {RequestInit} [options] Override http request option.

*/
reset(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Reset200Response> {
reset(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<boolean> {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).reset(options);

@@ -1040,3 +913,3 @@ return (fetch: FetchAPI = defaultFetch, basePath: string = BASE_PATH) => {

*/
root(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Root200Response> {
root(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<{ [name: string]: number }> {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).root(options);

@@ -1153,3 +1026,3 @@ return (fetch: FetchAPI = defaultFetch, basePath: string = BASE_PATH) => {

*/
version(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<Api.Version200Response> {
version(options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<string> {
const localVarFetchArgs = ApiApiFetchParamCreator(configuration).version(options);

@@ -1243,12 +1116,2 @@ return (fetch: FetchAPI = defaultFetch, basePath: string = BASE_PATH) => {

/**
* @summary Create Index
* @param {string} collectionName
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
public createIndex(collectionName: string, options?: RequestInit) {
return ApiApiFp(this.configuration).createIndex(collectionName, options)(this.fetch, this.basePath);
}
/**
* @summary Delete Collection

@@ -1303,12 +1166,2 @@ * @param {string} collectionName

/**
* @summary Raw Sql
* @param {Api.RawSql} request
* @param {RequestInit} [options] Override http request option.
* @throws {RequiredError}
*/
public rawSql(request: Api.RawSql, options?: RequestInit) {
return ApiApiFp(this.configuration).rawSql(request, options)(this.fetch, this.basePath);
}
/**
* @summary Reset

@@ -1315,0 +1168,0 @@ * @param {RequestInit} [options] Override http request option.

@@ -24,3 +24,2 @@ /* eslint-disable */

ids: string[];
'increment_index'?: boolean;
}

@@ -69,5 +68,2 @@

export interface CreateIndex200Response {
}
export interface DeleteCollection200Response {

@@ -157,5 +153,2 @@ }

export interface Heartbeat200Response {
}
export interface HTTPValidationError {

@@ -221,15 +214,2 @@ detail?: Api.ValidationError[];

export interface RawSql {
'raw_sql': string;
}
export interface RawSql200Response {
}
export interface Reset200Response {
}
export interface Root200Response {
}
export interface Update200Response {

@@ -261,3 +241,2 @@ }

ids: string[];
'increment_index'?: boolean;
}

@@ -287,5 +266,2 @@

export interface Version200Response {
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc