weaviate-client
Version:
JS/TS client for Weaviate
39 lines (38 loc) • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_js_1 = require("../collections/config/utils.js");
const errors_js_1 = require("../errors.js");
const util_js_1 = require("./util.js");
const tokenize = (connection, dbVersionSupport) => {
return {
text: (text, tokenization, opts) => {
if (opts?.stopwords !== undefined && opts?.stopwordPresets !== undefined) {
return Promise.reject(new errors_js_1.WeaviateInvalidInputError('stopwords and stopwordPresets are mutually exclusive; pass at most one'));
}
const hasStopwordsField = opts?.stopwords !== undefined || opts?.stopwordPresets !== undefined;
return dbVersionSupport
.supportsTokenize()
.then(({ supports, message }) => (supports ? Promise.resolve() : Promise.reject(new Error(message))))
.then(() => hasStopwordsField
? dbVersionSupport
.supportsTokenizeStopwords()
.then(({ supports, message }) => supports ? Promise.resolve() : Promise.reject(new Error(message)))
: Promise.resolve())
.then(() => connection
.postReturn('/tokenize', {
text,
tokenization,
analyzerConfig: (0, utils_js_1.textAnalyzerConfigToWire)(opts?.analyzerConfig),
stopwords: opts?.stopwords,
stopwordPresets: opts?.stopwordPresets,
})
.then(util_js_1.parseResult));
},
forProperty: (collection, property, text) => dbVersionSupport
.supportsTokenize()
.then(({ supports, message }) => (supports ? Promise.resolve() : Promise.reject(new Error(message))))
.then(() => connection.postReturn(`/schema/${collection}/properties/${property}/tokenize`, { text }))
.then(util_js_1.parseResult),
};
};
exports.default = tokenize;