Repository navigation
Index cached reviews for place search and chat #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { createReviewEvidenceScorer } from "../../public/scripts/place-search.js"; | ||
|
|
||
| // Review text is untrusted evidence, never instructions or verified place facts. | ||
| export function relevantReviewEvidence(entry, query, alternatives = []) { | ||
| const score = createReviewEvidenceScorer([query, ...alternatives].join(" ")); | ||
| return (Array.isArray(entry.review_evidence) ? entry.review_evidence : []) | ||
| .slice(0, 17) | ||
| .filter((text) => typeof text === "string") | ||
| .map((text, order) => { | ||
| const snippet = text.slice(0, 180); | ||
| return { snippet, order, score: score(snippet) }; | ||
| }) | ||
| .filter(({ score }) => score > 0) | ||
| .sort((a, b) => b.score - a.score || a.order - b.order) | ||
| .slice(0, 2) | ||
| .map(({ snippet }) => snippet); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { relevantReviewEvidence } from "../../functions/lib/chat-review-evidence.js"; | ||
|
|
||
| describe("chat review evidence budget", () => { | ||
| it("retains single-character CJK terms and folds Latin accents like retrieval", () => { | ||
| expect(relevantReviewEvidence({ review_evidence: ["鴨料理很好吃", "茶很好喝"] }, "鴨")).toEqual( | ||
| ["鴨料理很好吃"], | ||
| ); | ||
| expect(relevantReviewEvidence({ review_evidence: ["鴨料理很好吃", "茶很好喝"] }, "茶")).toEqual( | ||
| ["茶很好喝"], | ||
| ); | ||
| expect(relevantReviewEvidence({ review_evidence: ["Lovely café upstairs"] }, "cafe")).toEqual([ | ||
| "Lovely café upstairs", | ||
| ]); | ||
| }); | ||
|
|
||
| it("keeps evidence supported by retrieval atmosphere aliases", () => { | ||
| expect( | ||
| relevantReviewEvidence( | ||
| { review_evidence: ["Quiet upstairs seating", "Busy downstairs"] }, | ||
| "calm cafe", | ||
| ), | ||
| ).toEqual(["Quiet upstairs seating"]); | ||
| }); | ||
|
|
||
| it("selects relevant snippets with Unicode support and a fixed payload budget", () => { | ||
| const entry = { | ||
| review_evidence: [ | ||
| "Noisy downstairs.", | ||
| `Sesame pudding ${"x".repeat(400)}`, | ||
| "Pudding upstairs", | ||
| "Sesame pudding upstairs", | ||
| "小籠湯包很好吃", | ||
| ], | ||
| }; | ||
| expect(relevantReviewEvidence(entry, "sesame pudding upstairs")).toEqual([ | ||
| "Sesame pudding upstairs", | ||
| `Sesame pudding ${"x".repeat(165)}`, | ||
| ]); | ||
| expect(relevantReviewEvidence(entry, "小籠湯包")).toEqual(["小籠湯包很好吃"]); | ||
| expect(relevantReviewEvidence(entry, "soup dumplings", ["小籠湯包"])).toEqual([ | ||
| "小籠湯包很好吃", | ||
| ]); | ||
| expect(relevantReviewEvidence(entry, "ramen")).toEqual([]); | ||
| expect(relevantReviewEvidence({}, "ramen")).toEqual([]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.