Perplexica / src /utils /computeSimilarity.ts
Asman2010's picture
Upload 65 files
f5ed9bf verified
raw
history blame contribute delete
509 Bytes
import dot from 'compute-dot';
import cosineSimilarity from 'compute-cosine-similarity';
import { getSimilarityMeasure } from '../config';
const computeSimilarity = (x: number[], y: number[]): number => {
const similarityMeasure = getSimilarityMeasure();
if (similarityMeasure === 'cosine') {
return cosineSimilarity(x, y);
} else if (similarityMeasure === 'dot') {
return dot(x, y);
}
throw new Error('Invalid similarity measure');
};
export default computeSimilarity;