diff --git a/provider/docs/src/corpus/search/embeddings.test.ts b/provider/docs/src/corpus/search/embeddings.test.ts index 36198fd9..ac0e71ce 100644 --- a/provider/docs/src/corpus/search/embeddings.test.ts +++ b/provider/docs/src/corpus/search/embeddings.test.ts @@ -1,14 +1,15 @@ import { describe, expect, test } from 'vitest' import { indexCorpus, type CorpusSearchResult } from '..' +import { noopCache } from '../cache/cache' import { corpusData } from '../data' import { doc } from '../index.test' import { embeddingsSearch, embedTextInThisScope, similarity } from './embeddings' describe('embeddingsSearch', () => { test('finds matches', async () => { - expect(await embeddingsSearch(await indexCorpus(corpusData([doc(1, 'a'), doc(2, 'b')])), 'b')).toEqual< - CorpusSearchResult[] - >([{ doc: 2, chunk: 0, score: 1, excerpt: 'b' }]) + expect( + await embeddingsSearch(await indexCorpus(corpusData([doc(1, 'a'), doc(2, 'b')])), 'b', { cache: noopCache }) + ).toEqual([{ doc: 2, chunk: 0, score: 1, excerpt: 'b' }]) }) }) diff --git a/provider/docs/src/corpus/search/keyword.test.ts b/provider/docs/src/corpus/search/keyword.test.ts index 977f5a9e..087f041a 100644 --- a/provider/docs/src/corpus/search/keyword.test.ts +++ b/provider/docs/src/corpus/search/keyword.test.ts @@ -1,5 +1,6 @@ import { describe, expect, test } from 'vitest' import { indexCorpus, type CorpusSearchResult } from '..' +import { noopCache } from '../cache/cache' import { corpusData } from '../data' import { doc } from '../index.test' import { keywordSearch } from './keyword' @@ -7,9 +8,11 @@ import { calculateTFIDF } from './tfidf' describe('keywordSearch', () => { test('finds matches', async () => { - expect(keywordSearch(await indexCorpus(corpusData([doc(1, 'aaa'), doc(2, 'bbb')])), 'bbb')).toEqual< - CorpusSearchResult[] - >([ + expect( + await keywordSearch(await indexCorpus(corpusData([doc(1, 'aaa'), doc(2, 'bbb')])), 'bbb', { + cache: noopCache, + }) + ).toEqual([ { doc: 2, chunk: 0, diff --git a/provider/docs/src/corpus/search/tfidf.test.ts b/provider/docs/src/corpus/search/tfidf.test.ts index eef0e4cc..2010991a 100644 --- a/provider/docs/src/corpus/search/tfidf.test.ts +++ b/provider/docs/src/corpus/search/tfidf.test.ts @@ -1,9 +1,9 @@ import { describe, expect, test } from 'vitest' import { indexCorpus } from '..' import { corpusData } from '../data' -import { calculateTFIDF, createTFIDFIndex } from './tfidf' +import { calculateTFIDF, computeTFIDF, createTFIDFIndex } from './tfidf' -describe('createIndexForTFIDF', async () => { +describe('createTFIDFIndex', async () => { const data = corpusData([ { id: 1, text: 'a b c c c' }, { id: 2, text: 'b c d' }, @@ -11,10 +11,10 @@ describe('createIndexForTFIDF', async () => { ]) const docIDs = data.docs.map(({ id }) => id) const index = await indexCorpus(data) - const tfidf = createTFIDFIndex(index.docs) + const tfidfIndex = createTFIDFIndex(index.docs) test('term in 1 doc', () => { - expect(docIDs.map(docID => tfidf('a', docID, 0))).toEqual([ + expect(docIDs.map(docID => computeTFIDF('a', docID, 0, tfidfIndex))).toEqual([ calculateTFIDF({ termOccurrencesInChunk: 1, chunkTermLength: 5, totalChunks: 3, termChunkFrequency: 1 }), 0, 0, @@ -22,7 +22,7 @@ describe('createIndexForTFIDF', async () => { }) test('term in all docs', () => { - expect(docIDs.map(docID => tfidf('c', docID, 0))).toEqual([ + expect(docIDs.map(docID => computeTFIDF('c', docID, 0, tfidfIndex))).toEqual([ calculateTFIDF({ termOccurrencesInChunk: 3, chunkTermLength: 5, totalChunks: 3, termChunkFrequency: 3 }), calculateTFIDF({ termOccurrencesInChunk: 1, chunkTermLength: 3, totalChunks: 3, termChunkFrequency: 3 }), calculateTFIDF({ termOccurrencesInChunk: 1, chunkTermLength: 3, totalChunks: 3, termChunkFrequency: 3 }), @@ -30,6 +30,6 @@ describe('createIndexForTFIDF', async () => { }) test('unknown term', () => { - expect(docIDs.map(docID => tfidf('x', docID, 0))).toEqual([0, 0, 0]) + expect(docIDs.map(docID => computeTFIDF('x', docID, 0, tfidfIndex))).toEqual([0, 0, 0]) }) })