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.2.1 to 1.3.0

40

dist/main/index.d.ts
import { DefaultApi } from "./generated/api";
export declare class OpenAIEmbeddingFunction {
private api_key;
private org_id;
private model;
constructor(openai_api_key: string, openai_model: string, openai_organization_id: string);
generate(texts: string[]): Promise<any[]>;
}
export declare class CohereEmbeddingFunction {
private api_key;
constructor(cohere_api_key: string);
generate(texts: string[]): Promise<any>;
}
type CallableFunction = {
new (): CallableFunction;
generate(texts: string[]): number[][];
};
export declare class Collection {
private name;
name: string;
private api;
constructor(name: string, api: DefaultApi);
add(ids: string | Array<any>, embeddings: Array<any>, metadatas?: Array<any> | object, documents?: string | Array<any>, increment_index?: boolean): Promise<import("axios").AxiosResponse<any, any>>;
embeddingFunction: CallableFunction | undefined;
constructor(name: string, api: DefaultApi, embeddingFunction?: CallableFunction);
add(ids: string | string[], embeddings: number[] | number[][], metadatas?: object | object[], documents?: string | string[], increment_index?: boolean): Promise<any>;
count(): Promise<any>;
get(ids?: string[], where?: object, limit?: number, offset?: number): Promise<import("axios").AxiosResponse<any, any>>;
query(query_embeddings: number[], n_results?: number, where?: object): Promise<any>;
peek(limit?: number): Promise<import("axios").AxiosResponse<any, any>>;
get(ids?: string[], where?: object, limit?: number, offset?: number): Promise<any>;
query(query_embeddings: number[] | number[][], n_results?: number, where?: object, query_text?: string | string[]): Promise<any>;
peek(limit?: number): Promise<any>;
createIndex(): Promise<import("axios").AxiosResponse<any, any>>;
delete(ids?: string[], where?: object): Promise<import("axios").AxiosResponse<any, any>>;
delete(ids?: string[], where?: object): Promise<any>;
}
export declare class ChromaClient {
private api;
constructor(basePath: string);
constructor(basePath?: string);
reset(): Promise<import("axios").AxiosResponse<any, any>>;
createCollection(name: string, metadata?: object): Promise<Collection>;
createCollection(name: string, metadata?: object, embeddingFunction?: CallableFunction): Promise<Collection>;
listCollections(): Promise<any>;
getCollection(name: string): Promise<Collection>;
deleteCollection(name: string): Promise<import("axios").AxiosResponse<any, any>>;
getCollection(name: string, embeddingFunction?: CallableFunction): Promise<Collection>;
deleteCollection(name: string): Promise<any>;
}
export {};
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChromaClient = exports.Collection = void 0;
exports.ChromaClient = exports.Collection = exports.CohereEmbeddingFunction = exports.OpenAIEmbeddingFunction = void 0;
const api_1 = require("./generated/api");

@@ -24,8 +24,79 @@ const configuration_1 = require("./generated/configuration");

}
class EmbeddingFunction {
}
let OpenAIApi;
class OpenAIEmbeddingFunction {
constructor(openai_api_key, openai_model, openai_organization_id) {
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
OpenAIApi = require("openai");
}
catch (_a) {
throw new Error("Please install the openai package to use the OpenAIEmbeddingFunction, `npm install -S openai`");
}
this.api_key = openai_api_key;
this.org_id = openai_organization_id || "";
this.model = openai_model || "text-embedding-ada-002";
}
async generate(texts) {
const configuration = new OpenAIApi.Configuration({
organization: this.org_id,
apiKey: this.api_key,
});
const openai = new OpenAIApi.OpenAIApi(configuration);
const embeddings = [];
const response = await openai.createEmbedding({
model: "text-embedding-ada-002",
input: texts,
});
const data = response.data['data'];
for (let i = 0; i < data.length; i += 1) {
embeddings.push(data[i]['embedding']);
}
return embeddings;
}
}
exports.OpenAIEmbeddingFunction = OpenAIEmbeddingFunction;
let CohereAiApi;
class CohereEmbeddingFunction {
constructor(cohere_api_key) {
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
CohereAiApi = require("cohere-ai");
}
catch (_a) {
throw new Error("Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`");
}
this.api_key = cohere_api_key;
}
async generate(texts) {
const cohere = CohereAiApi.init(this.api_key);
const embeddings = [];
const response = await CohereAiApi.embed({
texts: texts,
});
return response.body.embeddings;
}
}
exports.CohereEmbeddingFunction = CohereEmbeddingFunction;
class Collection {
constructor(name, api) {
constructor(name, api, embeddingFunction) {
this.name = name;
this.api = api;
if (embeddingFunction !== undefined)
this.embeddingFunction = embeddingFunction;
}
async add(ids, embeddings, metadatas, documents, increment_index = true) {
if ((embeddings === undefined) && (documents === undefined)) {
throw new Error("embeddings and documents cannot both be undefined");
}
else if ((embeddings === undefined) && (documents !== undefined)) {
const documentsArray = toArray(documents);
if (this.embeddingFunction !== undefined) {
embeddings = await this.embeddingFunction.generate(documentsArray);
}
else {
throw new Error("embeddingFunction is undefined. Please configure an embedding function");
}
}
const idsArray = toArray(ids);

@@ -41,9 +112,9 @@ const embeddingsArray = toArrayOfArrays(embeddings);

let documentsArray;
if (metadatas === undefined) {
if (documents === undefined) {
documentsArray = undefined;
}
else {
documentsArray = toArray(metadatas);
documentsArray = toArray(documents);
}
if (idsArray.length !== embeddingsArray.length ||
if (((embeddingsArray !== undefined) && idsArray.length !== embeddingsArray.length) ||
((metadatasArray !== undefined) && idsArray.length !== metadatasArray.length) ||

@@ -53,3 +124,3 @@ ((documentsArray !== undefined) && idsArray.length !== documentsArray.length)) {

}
return await this.api.add({
const response = await this.api.add({
collectionName: this.name,

@@ -63,3 +134,8 @@ addEmbedding: {

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response;
}

@@ -71,4 +147,6 @@ async count() {

async get(ids, where, limit, offset) {
const idsArray = toArray(ids);
return await this.api.get({
let idsArray = undefined;
if (ids !== undefined)
idsArray = toArray(ids);
var resp = await this.api.get({
collectionName: this.name,

@@ -81,5 +159,22 @@ getEmbedding: {

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return resp;
}
async query(query_embeddings, n_results = 10, where) {
async query(query_embeddings, n_results = 10, where, query_text) {
if ((query_embeddings === undefined) && (query_text === undefined)) {
throw new Error("query_embeddings and query_text cannot both be undefined");
}
else if ((query_embeddings === undefined) && (query_text !== undefined)) {
const query_texts = toArray(query_text);
if (this.embeddingFunction !== undefined) {
query_embeddings = await this.embeddingFunction.generate(query_texts);
}
else {
throw new Error("embeddingFunction is undefined. Please configure an embedding function");
}
}
const query_embeddingsArray = toArrayOfArrays(query_embeddings);

@@ -93,10 +188,15 @@ const response = await this.api.getNearestNeighbors({

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response.data;
return response;
}
async peek(limit = 10) {
return await this.api.get({
const response = await this.api.get({
collectionName: this.name,
getEmbedding: { limit: limit },
});
return response.data;
}

@@ -107,6 +207,11 @@ async createIndex() {

async delete(ids, where) {
return await this.api._delete({
var response = await this.api._delete({
collectionName: this.name,
deleteEmbedding: { ids: ids, where: where },
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response;
}

@@ -117,2 +222,4 @@ }

constructor(basePath) {
if (basePath === undefined)
basePath = "http://localhost:8000";
const apiConfig = new configuration_1.Configuration({

@@ -126,7 +233,14 @@ basePath,

}
async createCollection(name, metadata) {
async createCollection(name, metadata, embeddingFunction) {
const newCollection = await this.api.createCollection({
createCollection: { name, metadata },
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return new Collection(name, this.api);
if (newCollection.error) {
throw new Error(newCollection.error);
}
return new Collection(name, this.api, embeddingFunction);
}

@@ -137,7 +251,12 @@ async listCollections() {

}
async getCollection(name) {
return new Collection(name, this.api);
async getCollection(name, embeddingFunction) {
return new Collection(name, this.api, embeddingFunction);
}
async deleteCollection(name) {
return await this.api.deleteCollection({ collectionName: name });
const response = await this.api.deleteCollection({ collectionName: name }).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response;
}

@@ -144,0 +263,0 @@ }

import { DefaultApi } from "./generated/api";
export declare class OpenAIEmbeddingFunction {
private api_key;
private org_id;
private model;
constructor(openai_api_key: string, openai_model: string, openai_organization_id: string);
generate(texts: string[]): Promise<any[]>;
}
export declare class CohereEmbeddingFunction {
private api_key;
constructor(cohere_api_key: string);
generate(texts: string[]): Promise<any>;
}
type CallableFunction = {
new (): CallableFunction;
generate(texts: string[]): number[][];
};
export declare class Collection {
private name;
name: string;
private api;
constructor(name: string, api: DefaultApi);
add(ids: string | Array<any>, embeddings: Array<any>, metadatas?: Array<any> | object, documents?: string | Array<any>, increment_index?: boolean): Promise<import("axios").AxiosResponse<any, any>>;
embeddingFunction: CallableFunction | undefined;
constructor(name: string, api: DefaultApi, embeddingFunction?: CallableFunction);
add(ids: string | string[], embeddings: number[] | number[][], metadatas?: object | object[], documents?: string | string[], increment_index?: boolean): Promise<any>;
count(): Promise<any>;
get(ids?: string[], where?: object, limit?: number, offset?: number): Promise<import("axios").AxiosResponse<any, any>>;
query(query_embeddings: number[], n_results?: number, where?: object): Promise<any>;
peek(limit?: number): Promise<import("axios").AxiosResponse<any, any>>;
get(ids?: string[], where?: object, limit?: number, offset?: number): Promise<any>;
query(query_embeddings: number[] | number[][], n_results?: number, where?: object, query_text?: string | string[]): Promise<any>;
peek(limit?: number): Promise<any>;
createIndex(): Promise<import("axios").AxiosResponse<any, any>>;
delete(ids?: string[], where?: object): Promise<import("axios").AxiosResponse<any, any>>;
delete(ids?: string[], where?: object): Promise<any>;
}
export declare class ChromaClient {
private api;
constructor(basePath: string);
constructor(basePath?: string);
reset(): Promise<import("axios").AxiosResponse<any, any>>;
createCollection(name: string, metadata?: object): Promise<Collection>;
createCollection(name: string, metadata?: object, embeddingFunction?: CallableFunction): Promise<Collection>;
listCollections(): Promise<any>;
getCollection(name: string): Promise<Collection>;
deleteCollection(name: string): Promise<import("axios").AxiosResponse<any, any>>;
getCollection(name: string, embeddingFunction?: CallableFunction): Promise<Collection>;
deleteCollection(name: string): Promise<any>;
}
export {};
//# sourceMappingURL=index.d.ts.map

@@ -21,8 +21,77 @@ import { DefaultApi } from "./generated/api";

}
class EmbeddingFunction {
}
let OpenAIApi;
export class OpenAIEmbeddingFunction {
constructor(openai_api_key, openai_model, openai_organization_id) {
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
OpenAIApi = require("openai");
}
catch (_a) {
throw new Error("Please install the openai package to use the OpenAIEmbeddingFunction, `npm install -S openai`");
}
this.api_key = openai_api_key;
this.org_id = openai_organization_id || "";
this.model = openai_model || "text-embedding-ada-002";
}
async generate(texts) {
const configuration = new OpenAIApi.Configuration({
organization: this.org_id,
apiKey: this.api_key,
});
const openai = new OpenAIApi.OpenAIApi(configuration);
const embeddings = [];
const response = await openai.createEmbedding({
model: "text-embedding-ada-002",
input: texts,
});
const data = response.data['data'];
for (let i = 0; i < data.length; i += 1) {
embeddings.push(data[i]['embedding']);
}
return embeddings;
}
}
let CohereAiApi;
export class CohereEmbeddingFunction {
constructor(cohere_api_key) {
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
CohereAiApi = require("cohere-ai");
}
catch (_a) {
throw new Error("Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`");
}
this.api_key = cohere_api_key;
}
async generate(texts) {
const cohere = CohereAiApi.init(this.api_key);
const embeddings = [];
const response = await CohereAiApi.embed({
texts: texts,
});
return response.body.embeddings;
}
}
export class Collection {
constructor(name, api) {
constructor(name, api, embeddingFunction) {
this.name = name;
this.api = api;
if (embeddingFunction !== undefined)
this.embeddingFunction = embeddingFunction;
}
async add(ids, embeddings, metadatas, documents, increment_index = true) {
if ((embeddings === undefined) && (documents === undefined)) {
throw new Error("embeddings and documents cannot both be undefined");
}
else if ((embeddings === undefined) && (documents !== undefined)) {
const documentsArray = toArray(documents);
if (this.embeddingFunction !== undefined) {
embeddings = await this.embeddingFunction.generate(documentsArray);
}
else {
throw new Error("embeddingFunction is undefined. Please configure an embedding function");
}
}
const idsArray = toArray(ids);

@@ -38,9 +107,9 @@ const embeddingsArray = toArrayOfArrays(embeddings);

let documentsArray;
if (metadatas === undefined) {
if (documents === undefined) {
documentsArray = undefined;
}
else {
documentsArray = toArray(metadatas);
documentsArray = toArray(documents);
}
if (idsArray.length !== embeddingsArray.length ||
if (((embeddingsArray !== undefined) && idsArray.length !== embeddingsArray.length) ||
((metadatasArray !== undefined) && idsArray.length !== metadatasArray.length) ||

@@ -50,3 +119,3 @@ ((documentsArray !== undefined) && idsArray.length !== documentsArray.length)) {

}
return await this.api.add({
const response = await this.api.add({
collectionName: this.name,

@@ -60,3 +129,8 @@ addEmbedding: {

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response;
}

@@ -68,4 +142,6 @@ async count() {

async get(ids, where, limit, offset) {
const idsArray = toArray(ids);
return await this.api.get({
let idsArray = undefined;
if (ids !== undefined)
idsArray = toArray(ids);
var resp = await this.api.get({
collectionName: this.name,

@@ -78,5 +154,22 @@ getEmbedding: {

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return resp;
}
async query(query_embeddings, n_results = 10, where) {
async query(query_embeddings, n_results = 10, where, query_text) {
if ((query_embeddings === undefined) && (query_text === undefined)) {
throw new Error("query_embeddings and query_text cannot both be undefined");
}
else if ((query_embeddings === undefined) && (query_text !== undefined)) {
const query_texts = toArray(query_text);
if (this.embeddingFunction !== undefined) {
query_embeddings = await this.embeddingFunction.generate(query_texts);
}
else {
throw new Error("embeddingFunction is undefined. Please configure an embedding function");
}
}
const query_embeddingsArray = toArrayOfArrays(query_embeddings);

@@ -90,10 +183,15 @@ const response = await this.api.getNearestNeighbors({

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response.data;
return response;
}
async peek(limit = 10) {
return await this.api.get({
const response = await this.api.get({
collectionName: this.name,
getEmbedding: { limit: limit },
});
return response.data;
}

@@ -104,6 +202,11 @@ async createIndex() {

async delete(ids, where) {
return await this.api._delete({
var response = await this.api._delete({
collectionName: this.name,
deleteEmbedding: { ids: ids, where: where },
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response;
}

@@ -113,2 +216,4 @@ }

constructor(basePath) {
if (basePath === undefined)
basePath = "http://localhost:8000";
const apiConfig = new Configuration({

@@ -122,7 +227,14 @@ basePath,

}
async createCollection(name, metadata) {
async createCollection(name, metadata, embeddingFunction) {
const newCollection = await this.api.createCollection({
createCollection: { name, metadata },
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return new Collection(name, this.api);
if (newCollection.error) {
throw new Error(newCollection.error);
}
return new Collection(name, this.api, embeddingFunction);
}

@@ -133,9 +245,14 @@ async listCollections() {

}
async getCollection(name) {
return new Collection(name, this.api);
async getCollection(name, embeddingFunction) {
return new Collection(name, this.api, embeddingFunction);
}
async deleteCollection(name) {
return await this.api.deleteCollection({ collectionName: name });
const response = await this.api.deleteCollection({ collectionName: name }).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response;
}
}
//# sourceMappingURL=index.js.map
{
"name": "chromadb",
"version": "1.2.1",
"version": "1.3.0",
"description": "A JavaScript interface for chroma",

@@ -10,4 +10,10 @@ "keywords": [],

"@openapitools/openapi-generator-cli": "^2.5.2",
"@types/jest": "^29.4.0",
"jest": "^29.4.3",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"tsd": "^0.24.1",
"typescript": "^4.5.5"
},

@@ -24,2 +30,9 @@ "dependencies": {

"scripts": {
"test": "run-s db:clean db:run test:runfull db:clean",
"test:set-port": "cross-env URL=localhost:8001",
"test:run": "jest --runInBand",
"test:runfull": "PORT=8001 jest --runInBand",
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot && run-s db:clean",
"db:clean": "cd ../.. && docker-compose -f docker-compose-js-tests.yml down --volumes",
"db:run": "cd ../.. && docker-compose -f docker-compose-js-tests.yml up --detach && sleep 5",
"clean": "rimraf dist",

@@ -26,0 +39,0 @@ "build": "run-s clean build:*",

@@ -22,18 +22,109 @@ import { DefaultApi } from "./generated/api";

class EmbeddingFunction { }
let OpenAIApi: any;
export class OpenAIEmbeddingFunction {
private api_key: string;
private org_id: string;
private model: string;
constructor(openai_api_key: string, openai_model: string, openai_organization_id: string) {
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
OpenAIApi = require("openai");
} catch {
throw new Error(
"Please install the openai package to use the OpenAIEmbeddingFunction, `npm install -S openai`",
);
}
this.api_key = openai_api_key;
this.org_id = openai_organization_id || "";
this.model = openai_model || "text-embedding-ada-002";
}
public async generate(texts: string[]) {
const configuration = new OpenAIApi.Configuration({
organization: this.org_id,
apiKey: this.api_key,
});
const openai = new OpenAIApi.OpenAIApi(configuration);
const embeddings = [];
const response = await openai.createEmbedding({
model: "text-embedding-ada-002",
input: texts,
});
const data = response.data['data'];
for (let i = 0; i < data.length; i += 1) {
embeddings.push(data[i]['embedding']);
}
return embeddings;
}
}
let CohereAiApi: any;
export class CohereEmbeddingFunction {
private api_key: string;
constructor(cohere_api_key: string) {
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
CohereAiApi = require("cohere-ai");
} catch {
throw new Error(
"Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`",
);
}
this.api_key = cohere_api_key;
}
public async generate(texts: string[]) {
const cohere = CohereAiApi.init(this.api_key);
const embeddings = [];
const response = await CohereAiApi.embed({
texts: texts,
});
return response.body.embeddings;
}
}
type CallableFunction = {
new(): CallableFunction;
generate(texts: string[]): number[][];
};
export class Collection {
private name: string;
public name: string;
private api: DefaultApi;
public embeddingFunction: CallableFunction | undefined;
constructor(name: string, api: DefaultApi) {
constructor(name: string, api: DefaultApi, embeddingFunction?: CallableFunction) {
this.name = name;
this.api = api;
if (embeddingFunction !== undefined)
this.embeddingFunction = embeddingFunction;
}
public async add(
ids: string | Array<any>,
embeddings: Array<any>,
metadatas?: Array<any> | object,
documents?: string | Array<any>,
ids: string | string[],
embeddings: number[] | number[][],
metadatas?: object | object[],
documents?: string | string[],
increment_index: boolean = true,
) {
if ((embeddings === undefined) && (documents === undefined)) {
throw new Error(
"embeddings and documents cannot both be undefined",
);
} else if ((embeddings === undefined) && (documents !== undefined)) {
const documentsArray = toArray(documents);
if (this.embeddingFunction !== undefined) {
embeddings = await this.embeddingFunction.generate(documentsArray)
} else {
throw new Error(
"embeddingFunction is undefined. Please configure an embedding function",
);
}
}

@@ -43,3 +134,3 @@ const idsArray = toArray(ids);

let metadatasArray;
let metadatasArray: object[] | undefined;
if (metadatas === undefined) {

@@ -51,11 +142,11 @@ metadatasArray = undefined

let documentsArray;
if (metadatas === undefined) {
let documentsArray: (string | undefined)[] | undefined;
if (documents === undefined) {
documentsArray = undefined
} else {
documentsArray = toArray(metadatas);
documentsArray = toArray(documents);
}
if (
idsArray.length !== embeddingsArray.length ||
((embeddingsArray !== undefined) && idsArray.length !== embeddingsArray.length) ||
((metadatasArray !== undefined) && idsArray.length !== metadatasArray.length) ||

@@ -69,3 +160,3 @@ ((documentsArray !== undefined) && idsArray.length !== documentsArray.length)

return await this.api.add({
const response = await this.api.add({
collectionName: this.name,

@@ -79,3 +170,9 @@ addEmbedding: {

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response
}

@@ -94,5 +191,6 @@

) {
const idsArray = toArray(ids);
let idsArray = undefined
if (ids !== undefined) idsArray = toArray(ids);
return await this.api.get({
var resp = await this.api.get({
collectionName: this.name,

@@ -105,10 +203,33 @@ getEmbedding: {

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return resp
}
public async query(
query_embeddings: number[],
query_embeddings: number[] | number[][],
n_results: number = 10,
where?: object,
query_text?: string | string[],
) {
if ((query_embeddings === undefined) && (query_text === undefined)) {
throw new Error(
"query_embeddings and query_text cannot both be undefined",
);
} else if ((query_embeddings === undefined) && (query_text !== undefined)) {
const query_texts = toArray(query_text);
if (this.embeddingFunction !== undefined) {
query_embeddings = await this.embeddingFunction.generate(query_texts)
} else {
throw new Error(
"embeddingFunction is undefined. Please configure an embedding function",
);
}
}
const query_embeddingsArray = toArrayOfArrays(query_embeddings);

@@ -123,11 +244,17 @@

},
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response.data;
return response;
}
public async peek(limit: number = 10) {
return await this.api.get({
const response = await this.api.get({
collectionName: this.name,
getEmbedding: { limit: limit },
});
return response.data;
}

@@ -140,6 +267,12 @@

public async delete(ids?: string[], where?: object) {
return await this.api._delete({
var response = await this.api._delete({
collectionName: this.name,
deleteEmbedding: { ids: ids, where: where },
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response
}

@@ -152,3 +285,4 @@

constructor(basePath: string) {
constructor(basePath?: string) {
if (basePath === undefined) basePath = "http://localhost:8000";
const apiConfig: Configuration = new Configuration({

@@ -164,7 +298,16 @@ basePath,

public async createCollection(name: string, metadata?: object) {
public async createCollection(name: string, metadata?: object, embeddingFunction?: CallableFunction) {
const newCollection = await this.api.createCollection({
createCollection: { name, metadata },
}).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return new Collection(name, this.api);
if (newCollection.error) {
throw new Error(newCollection.error);
}
return new Collection(name, this.api, embeddingFunction);
}

@@ -177,10 +320,16 @@

public async getCollection(name: string) {
return new Collection(name, this.api);
public async getCollection(name: string, embeddingFunction?: CallableFunction) {
return new Collection(name, this.api, embeddingFunction);
}
public async deleteCollection(name: string) {
return await this.api.deleteCollection({ collectionName: name });
const response = await this.api.deleteCollection({ collectionName: name }).then(function (response) {
return response.data;
}).catch(function ({ response }) {
return response.data;
});
return response
}
}

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