Skip to content

Commit db55bc6

Browse files
Merge pull request #21 from epsilla-cloud/auto-embedding
Support auto embedding
2 parents 323eabf + 82ff488 commit db55bc6

File tree

5 files changed

+47
-21
lines changed

5 files changed

+47
-21
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "epsillajs",
3-
"version": "0.2.4",
3+
"version": "0.3.0",
44
"description": "A JS library to connect Epsilla vector database",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/cloud.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import axios, { AxiosError } from 'axios';
2-
import { DeleteRecordsConfig, EpsillaResponse, PreviewConfig, QueryConfig, TableField } from './models';
2+
import { DeleteRecordsConfig, EpsillaResponse, Index, PreviewConfig, QueryConfig, TableField } from './models';
33

44
export interface CloudClientConfig {
55
projectID: string;
66
apiKey: string;
7+
headers?: { [key: string]: string };
78
}
89

910
const dispatchDomain = 'https://dispatch.epsilla.com';
@@ -21,9 +22,12 @@ export class EpsillaCloud {
2122
projectID: string;
2223
headers: any;
2324

24-
constructor({ projectID, apiKey }: CloudClientConfig) {
25+
constructor({ projectID, apiKey, headers = {} }: CloudClientConfig) {
2526
this.projectID = projectID;
2627
this.headers = { 'Content-type': 'application/json', 'X-API-KEY': apiKey };
28+
if (headers) {
29+
this.headers = { ...this.headers, ...headers };
30+
}
2731
}
2832
}
2933

@@ -58,15 +62,19 @@ export class VectorDB {
5862
}
5963
}
6064

61-
async createTable(tableName: string, fields: TableField[]) {
65+
async createTable(tableName: string, fields: TableField[], indices?: Index[]) {
6266
try {
6367
const domain = this.host || dispatchDomain;
68+
let payload: any = {
69+
name: tableName,
70+
fields
71+
};
72+
if (indices) {
73+
payload['indices'] = indices;
74+
}
6475
const response = await axios.post(
6576
`${domain}/api/v3/project/${this.projectID}/vectordb/${this.dbID}/table/create`,
66-
{
67-
name: tableName,
68-
fields
69-
},
77+
payload,
7078
{ headers: this.headers }
7179
);
7280
return response.data;

src/models.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,34 @@ export interface TableField {
1313
metricType?: string;
1414
}
1515

16+
export interface Index {
17+
name: string;
18+
field: string;
19+
model?: string;
20+
}
21+
1622
export interface SparseVector {
1723
indices: number[];
1824
values: number[];
1925
}
2026

2127
export interface QueryPayload {
2228
table: string;
23-
queryField: string;
24-
queryVector: number[] | SparseVector;
29+
query?: string;
30+
queryIndex?: string;
31+
queryField?: string;
32+
queryVector?: number[] | SparseVector;
2533
limit: number;
2634
response?: string[];
2735
filter?: string;
2836
withDistance?: boolean;
2937
}
3038

3139
export interface QueryConfig {
32-
queryField: string;
33-
queryVector: number[] | SparseVector;
40+
query?: string;
41+
queryIndex?: string;
42+
queryField?: string;
43+
queryVector?: number[] | SparseVector;
3444
limit: number;
3545
response?: string[];
3646
filter?: string;

src/vectordb.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import axios, { AxiosError } from 'axios';
22
import {
3-
DeleteRecordsConfig, EpsillaResponse, LoadDBPayload,
3+
DeleteRecordsConfig, EpsillaResponse, Index, LoadDBPayload,
44
PreviewConfig, QueryConfig, QueryPayload, TableField
55
} from './models';
66

77
export interface ClientConfig {
88
protocol?: string;
99
host?: string;
1010
port?: number;
11+
headers?: { [key: string]: string };
1112
}
1213

1314
class EpsillaDB {
@@ -18,13 +19,16 @@ class EpsillaDB {
1819
private baseurl: string;
1920
private headers: any;
2021

21-
constructor({ protocol = 'http', host = 'localhost', port = 8888 }: ClientConfig = {}) {
22+
constructor({ protocol = 'http', host = 'localhost', port = 8888, headers = {} }: ClientConfig = {}) {
2223
this.protocol = protocol;
2324
this.host = host;
2425
this.port = port;
2526
this.db = null;
2627
this.baseurl = `${this.protocol}://${this.host}:${this.port}`;
2728
this.headers = { 'Content-type': 'application/json' };
29+
if (headers) {
30+
this.headers = { ...this.headers, ...headers };
31+
}
2832
}
2933

3034
useDB(dbName: string) {
@@ -65,17 +69,21 @@ class EpsillaDB {
6569
}
6670
}
6771

68-
async createTable(tableName: string, fields: TableField[]): Promise<EpsillaResponse | Error> {
72+
async createTable(tableName: string, fields: TableField[], indices?: Index[]): Promise<EpsillaResponse | Error> {
6973
if (!this.db) {
7074
console.error('[ERROR] Please useDB() first!');
7175
return new Error('[ERROR] Please useDB() first!');
7276
}
7377
try {
78+
let payload: any = {
79+
name: tableName,
80+
fields
81+
};
82+
if (indices) {
83+
payload['indices'] = indices;
84+
}
7485
const response = await axios.post(`${this.baseurl}/api/${this.db}/schema/tables`,
75-
{
76-
name: tableName,
77-
fields
78-
},
86+
payload,
7987
{ headers: this.headers }
8088
);
8189
return response.data;

0 commit comments

Comments
 (0)