UNPKG

weaviate-client

Version:
60 lines (59 loc) • 2.56 kB
import { WeaviateUnsupportedFeatureError } from '../../errors.js'; import { Serialize } from '../serialize/index.js'; export class Check { connection; name; dbVersionSupport; consistencyLevel; tenant; constructor(connection, name, dbVersionSupport, consistencyLevel, tenant) { this.connection = connection; this.name = name; this.dbVersionSupport = dbVersionSupport; this.consistencyLevel = consistencyLevel; this.tenant = tenant; } getSearcher = (callOpts) => this.connection.search(this.name, this.consistencyLevel, this.tenant, callOpts?.abortSignal); checkSupportForVectors = async (vec) => { if (vec === undefined || Serialize.isHybridNearTextSearch(vec)) return false; const check = await this.dbVersionSupport.supportsVectorsFieldInGRPC(); return check.supports; }; supportForSingleGroupedGenerative = async () => { const check = await this.dbVersionSupport.supportsSingleGrouped(); if (!check.supports) throw new WeaviateUnsupportedFeatureError(check.message); return check.supports; }; supportForGenerativeConfigRuntime = async (generativeConfig) => { if (generativeConfig === undefined) return true; const check = await this.dbVersionSupport.supportsGenerativeConfigRuntime(); if (!check.supports) throw new WeaviateUnsupportedFeatureError(check.message); return check.supports; }; nearSearch = (callOpts) => this.getSearcher(callOpts).then((search) => ({ search })); nearVector = (vec, opts, callOpts) => { return Promise.all([this.getSearcher(callOpts), this.checkSupportForVectors(vec)]).then(([search, supportsVectors]) => { const is129 = supportsVectors; return { search, supportsVectors: is129, }; }); }; hybridSearch = (opts, callOpts) => { return Promise.all([this.getSearcher(callOpts), this.checkSupportForVectors(opts?.vector)]).then(([search, supportsVectors]) => { const is129 = supportsVectors; return { search, supportsVectors: is129, }; }); }; fetchObjects = (callOpts) => this.getSearcher(callOpts).then((search) => ({ search })); fetchObjectById = (callOpts) => this.getSearcher(callOpts).then((search) => ({ search })); bm25 = (callOpts) => this.getSearcher(callOpts).then((search) => ({ search })); }