Skip to content
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

Chat: unify keyword rewrite and extraction #6767

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jtibshirani
Copy link
Member

@jtibshirani jtibshirani commented Jan 23, 2025

In #6655 we introduced a method for extracting keywords from chat questions that look like simple searches. Looking into the prompt, it's actually an improvement over our current prompt in rewriteKeywordQuery. It also fixes a bug where we failed to parse the response when it contained a single keyword. This PR switches to the new extractKeywords method to unify our approach.

Other changes:

  • Make the "should rewrite keyword" heuristic more lenient, also rewriting whenever the question includes a newline
  • Update Cody chat bench to include the rewritten query, so we can visualize it in cody-leaderboard

Test plan

Adapted unit tests. Reran context evals -- see next comment for results.

@jtibshirani
Copy link
Member Author

Usually we run the context evals without query rewriting. I enabled rewriting, then ran the baseline vs. the changes in this PR. The results are extremely similar:

Screenshot 2025-01-22 at 8 39 52 PM

Moreover, when examining the rewritten queries, they tended to be les noisy, and to better preserve symbols from the query.

Aside: I think we should run evals with query rewriting enabled by default, to better match the chat experience.

@@ -10,7 +10,7 @@ import { outputChannelLogger } from '../output-channel-logger'

import { francAll } from 'franc-min'

const containsMultipleSentences = /[.!?][\s\r\n]+\w/
const containsMultipleSentences = /[\n\r]|[.!?]\s*\w/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up, I'll look into removing this heuristic altogether. Previously in evals, we saw that rewriting tends to make performance much worse for simple queries. However, the new rewrite strategy is "lighter touch", so I'm hopeful it will work well even for short queries. It will be a nice behavior simplification to always rewrite, instead of having a heuristic here.

@@ -118,7 +60,7 @@ export async function extractKeywords(
...preamble,
{
speaker: 'human',
text: ps`You are helping the user search over a codebase. List terms that could be found literally in code snippets or file names relevant to answering the user's query. Limit your results to terms that are in the user's query. Present your results in a *single* XML list in the following format: <keywords><keyword>a single keyword</keyword></keywords>. Here is the user query: <userQuery>${query}</userQuery>`,
text: ps`You are helping the user search over a codebase. List English terms that could be found literally in code snippets or file names relevant to answering the user's query. Limit your results to terms that are in the user's query. Present your results in a *single* XML list in the following format: <keywords><keyword>a single keyword</keyword></keywords>. Here is the user query: <userQuery>${query}</userQuery>`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add 'English' here to keep the nice behavior where we translate foreign languages to common English code terms. I was worried that the LLM might start excluding symbols or acronyms because of this, but I see no evidence of that... many rewritten queries still contain terms like symf, zoekt, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant