Spaces:
Running
Running
Sync from felladrin/MiniSearch@9824a0b
Browse filesFiles changed (7)
19686d6219824a0b
1 unmodified line23456781 unmodified line# Renovate keeps this pin current via the customManager in renovate.json,# whose regex matches this exact line: keep the quoted 40-character form.ARG SEARXNG_COMMIT_SHA="c6ee3e9fd0235004a694e63720efc869bb1e3594"ENV PORT=7860EXPOSE $PORT1 unmodified line23456781 unmodified line# Renovate keeps this pin current via the customManager in renovate.json,# whose regex matches this exact line: keep the quoted 40-character form.ARG SEARXNG_COMMIT_SHA="254cb81591b13db0814f1dd2f38e20143839681a"ENV PORT=7860EXPOSE $PORT
1 unmodified line2345671 unmodified lineNotable changes, grouped by date, most recent first.## 2026-11-29- Future timestamps now show their locale date instead of being reported as just now.1 unmodified line234567891011121 unmodified lineNotable changes, grouped by date, most recent first.## 2026-11-30- Page excerpts now stay within their shared token budget when they are shortened, leaving the rest of the model's context available for the answer.- Searches whose query text resembles cache-key metadata no longer reuse results cached for a different query or filter.## 2026-11-29- Future timestamps now show their locale date instead of being reported as just now.
12348 unmodified lines52535455import { describe, expect, it } from "vitest";import { allocatePageExcerpts } from "./pageExcerptAllocation";48 unmodified lines"",]);});});123448 unmodified lines5354555657585960616263646566676869import gptTokenizer from "gpt-tokenizer";import { describe, expect, it } from "vitest";import { allocatePageExcerpts } from "./pageExcerptAllocation";48 unmodified lines"",]);});it("keeps the encoded excerpts within the shared budget when truncating", () => {const contents = Array(6).fill("a much longer page. ".repeat(2000));const tokenBudget = 1433;const excerpts = allocatePageExcerpts(contents, tokenBudget);const usedTokens = excerpts.reduce((total, excerpt) => total + gptTokenizer.encode(excerpt).length,0,);expect(excerpts.every((excerpt) => excerpt.endsWith("โฆ"))).toBe(true);expect(usedTokens).toBeLessThanOrEqual(tokenBudget);});});
28 unmodified lines2930313233343536373839404142434445464728 unmodified lineslet remainingPages = pending.length;for (const { index, tokens } of pending) {const taken = Math.min(tokens.length,Math.floor(remainingBudget / remainingPages),);if (taken > 0) {excerpts[index] =taken === tokens.length? contents[index]: `${gptTokenizer.decode(tokens.slice(0, taken)).trimEnd()}โฆ`;}remainingBudget -= taken;remainingPages--;}28 unmodified lines29303132333435363738394041424344454647484950515228 unmodified lineslet remainingPages = pending.length;for (const { index, tokens } of pending) {const share = Math.floor(remainingBudget / remainingPages);if (tokens.length <= share) {excerpts[index] = contents[index];remainingBudget -= tokens.length;} else {for (let taken = Math.min(tokens.length - 1, share); taken > 0; taken--) {const excerpt = `${gptTokenizer.decode(tokens.slice(0, taken)).trimEnd()}โฆ`;const excerptTokenCount = gptTokenizer.encode(excerpt).length;if (excerptTokenCount <= share) {excerpts[index] = excerpt;remainingBudget -= excerptTokenCount;break;}}}remainingPages--;}
92 unmodified lines939495969798563 unmodified lines66266366466566666792 unmodified linesexpect(result1).not.toBe(result2);});it("should include limit in the hash so different limits produce different keys", async () => {const hashNoLimit =await searchModule.searchServiceInstance.hashQuery("test query");563 unmodified linesexpect(mockFetch).toHaveBeenCalledTimes(2);});it("should treat different limits as separate cache entries", async () => {const mockResults: string[][] = [["Title", "Snippet", "https://example.com"],92 unmodified lines93949596979899100101102103104105106107108109110111112563 unmodified lines67667767867968068168268368468568668768868969069169269369469569669769869992 unmodified linesexpect(result1).not.toBe(result2);});it("should distinguish literal cache-key suffixes from search options", async () => {const { hashQuery } = searchModule.searchServiceInstance;expect(await hashQuery("query::limit=5")).not.toBe(await hashQuery("query", 5),);expect(await hashQuery("query::time_range=week")).not.toBe(await hashQuery("query", undefined, "week"),);expect(await hashQuery("query::language=en-US")).not.toBe(await hashQuery("query", undefined, undefined, "en-US"),);});it("should include limit in the hash so different limits produce different keys", async () => {const hashNoLimit =await searchModule.searchServiceInstance.hashQuery("test query");563 unmodified linesexpect(mockFetch).toHaveBeenCalledTimes(2);});it("should not reuse results when a query contains a cache-key suffix", async () => {const literalQueryResults: string[][] = [["Literal query", "Literal snippet", "https://literal.example.com"],];const limitedQueryResults: string[][] = [["Limited query", "Limited snippet", "https://limited.example.com"],];mockFetch.mockResolvedValueOnce(searchResponse(literalQueryResults)).mockResolvedValueOnce(searchResponse(limitedQueryResults));await searchModule.searchText("search::limit=5");const outcome = await searchModule.searchText("search", 5);expect(mockFetch).toHaveBeenCalledTimes(2);expect(outcome.results).toEqual(limitedQueryResults);});it("should treat different limits as separate cache entries", async () => {const mockResults: string[][] = [["Title", "Snippet", "https://example.com"],
617 unmodified lines6186196206216226236246256261 unmodified line628629630631632633634635636617 unmodified lines/*** The limit, the time range and the language are part of the key, so neither* a different limit nor a different period nor a different language can read* another one's results. A search with no language and an Anytime search add* nothing, so they keep reading the entries cached before those settings* existed.*/async hashQuery(query: string,1 unmodified linetimeRange?: SearchTimeRange,language?: string,): Promise<string> {let input = limit !== undefined ? `${query}::limit=${limit}` : query;if (timeRange && timeRange !== "any") input += `::time_range=${timeRange}`;if (language) input += `::language=${language}`;const hash = await sha256(input);// 16 hex chars are enough for a cache key.return hash.slice(0, 16);617 unmodified lines6186196206216226236246256266276286291 unmodified line631632633634635636637638639640641642617 unmodified lines/*** The limit, the time range and the language are part of the key, so neither* a different limit nor a different period nor a different language can read* another one's results. The tuple is encoded as JSON rather than appended to* the query, because query text that reads like an option suffix - a search* for `search::limit=5` - would otherwise build another search's key and* return that search's results. A search with no language and an Anytime* search normalize to the same tuple, so they keep reading each other's* entries.*/async hashQuery(query: string,1 unmodified linetimeRange?: SearchTimeRange,language?: string,): Promise<string> {const input = JSON.stringify([query,limit ?? null,timeRange && timeRange !== "any" ? timeRange : null,language || null,]);const hash = await sha256(input);// 16 hex chars are enough for a cache key.return hash.slice(0, 16);
.source-commit+1-1
Dockerfile+1-1
changelog.md+5
client/modules/pageExcerptAllocation.test.ts+14
client/modules/pageExcerptAllocation.ts+15-10
client/modules/search.test.ts+32
client/modules/search.ts+12-6