diff --git a/package-lock.json b/package-lock.json index b5b4b0d..5a72069 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "epsillajs", - "version": "0.3.5", + "version": "0.3.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "epsillajs", - "version": "0.3.5", + "version": "0.3.6", "license": "Apache-2", "dependencies": { "axios": "^1.4.0" diff --git a/package.json b/package.json index 0c14df5..0e12931 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "epsillajs", - "version": "0.3.5", + "version": "0.3.6", "description": "A JS library to connect Epsilla vector database", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/models.ts b/src/models.ts index 07b7b2c..af68bac 100644 --- a/src/models.ts +++ b/src/models.ts @@ -24,6 +24,7 @@ export interface Index { name: string; field: string; model?: string; + dimensions?: number; } export interface SparseVector { @@ -41,6 +42,12 @@ export interface QueryPayload { response?: string[]; filter?: string; withDistance?: boolean; + facets?: FacetConfig[]; +} + +export interface FacetConfig { + group?: string[]; + aggregate: string[]; } export interface QueryConfig { @@ -52,6 +59,7 @@ export interface QueryConfig { response?: string[]; filter?: string; withDistance?: boolean; + facets?: FacetConfig[]; } export interface DeleteRecordsConfig { @@ -65,6 +73,7 @@ export interface PreviewConfig { filter?: string; skip?: number; limit?: number; + facets?: FacetConfig[]; } export interface EpsillaBaseResponse { diff --git a/src/searchengine.ts b/src/searchengine.ts index aad1dbe..e51c73f 100644 --- a/src/searchengine.ts +++ b/src/searchengine.ts @@ -1,13 +1,13 @@ // VectorRetriever.ts +import { VectorDB } from './cloud'; import { QueryPayload, - SearchEngineCandidate, Reranker, - RetrieverConfig, RerankerConfig, + RetrieverConfig, + SearchEngineCandidate } from './models'; import EpsillaDB from './vectordb'; -import { VectorDB } from './cloud'; export class VectorRetriever { private dbClient: EpsillaDB | VectorDB; @@ -29,7 +29,7 @@ export class VectorRetriever { queryVector?: any, response?: string[], limit: number = 2, - filter: string = '', + filter: string = '' ) { this.dbClient = dbClient; this.table = table; @@ -52,7 +52,7 @@ export class VectorRetriever { response: this.response, limit: this.limit, filter: this.filter, - withDistance: true, + withDistance: true }; const response = await this.dbClient.query(this.table, queryPayload); if (response instanceof Error) { @@ -155,7 +155,7 @@ export class RelativeScoreFusionReranker implements Reranker { if (aggregatedScores[id]) { aggregatedScores[id].score += normalizedScore as number; } else { - aggregatedScores[id] = { + aggregatedScores[id] = { candidate: list.find(candidate => candidate['@id'] === id) as SearchEngineCandidate, score: normalizedScore as number }; @@ -202,7 +202,7 @@ export class DistributionBasedScoreFusionReranker implements Reranker { throw new Error("The length of scaleRanges should be equal to the number of candidates lists."); } - const normalizedLists = candidatesLists.map((list, index) => + const normalizedLists = candidatesLists.map((list, index) => this.normalizeDistances(this.scaleRanges[index], list) );