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

Deep Cody: skip query rewrite for search tool #6082

Merged
merged 2 commits into from
Nov 7, 2024
Merged

Deep Cody: skip query rewrite for search tool #6082

merged 2 commits into from
Nov 7, 2024

Conversation

abeatrix
Copy link
Contributor

@abeatrix abeatrix commented Nov 7, 2024

This change adds a skipQueryRewrite option to the ContextRetriever.retrieveContext method, which is used when retrieving context for the Search tool.

This allows the Deep Cody to bypass the query rewriting step that makes an extra LLM request when using the search tool. The reason behind this is because Deep Cody has already return a proper search query that doesn't need rewritten into keyword.

The ContextRetriever._retrieveContext method has been updated to handle the skipQueryRewrite option, and the SearchTool class now passes true for this option when calling retrieveContext.

Minor prompt improvement (formatting and wording).

I've also notice some response quality regression after switching to use 3.5 Haiku for the reviewing step, where Haiku was not able to fetch the right context resulting in the wrong answer. Switching back to 3.5 Haiku:

Screenshot 2024-11-07 at 1 15 23 AM

Test plan

After: took 8797.651249999995ms to complete 2 review loops

█ Autocomplete:onComplete duration:"2378ms" stopReason:"undefined" outputChannelId:"69506ce2-38f2-4619-879b-71ef81187d02": {
  "completion": "<TOOLSEARCH><query>convertGitCloneURLToCodebaseName function implementation</query></TOOLSEARCH>"
}
█ CodyTool searching codebase for convertGitCloneURLToCodebaseName function implementation:
█ Autocomplete:onComplete duration:"3477ms" stopReason:"undefined" outputChannelId:"739cf779-96fd-47da-8aa3-9225b699617e": {
  "completion": "<TOOLSEARCH><query>convertGitCloneURLToCodebaseName SSH URL parsing</query></TOOLSEARCH>"
}
█ CodyTool searching codebase for convertGitCloneURLToCodebaseName SSH URL parsing:
█ telemetry-v2 recordEvent: cody.deep-cody.context/reviewed: {
  "parameters": {
    "version": 0,
    "privateMetadata": {
      "durationMs": 8797.651249999995,
      "context": 42,
      "loop": 2,
      "model": "anthropic::2024-10-22::claude-3-5-haiku-latest"
    },
    "billingMetadata": {
      "product": "cody",
      "category": "billable"
    }
  },
  "timestamp": "2024-11-07T08:15:03.589Z"
}

Example 2: " what models are available for dotcom users defined in the codebase?"

image

completion time: 6397.538499999995ms

█ Autocomplete:onComplete duration:"2789ms" stopReason:"undefined" outputChannelId:"73fcb0e4-fddb-4de5-894e-d95112ab5ba7": {
  "completion": "<TOOLSEARCH><query>available LLM models for dotcom users</query></TOOLSEARCH>"
}
█ CodyTool searching codebase for available LLM models for dotcom users:
█ Autocomplete:onComplete duration:"2138ms" stopReason:"undefined" outputChannelId:"c94a48a7-0a76-4283-a097-ca2b946b70dd": {
  "completion": "<TOOLFILE><name>/lib/shared/src/models/dotcom.ts</name></TOOLFILE>"
}
█ CodyTool requesting 1 files:
█ telemetry-v2 recordEvent: cody.deep-cody.context/reviewed: {
  "parameters": {
    "version": 0,
    "privateMetadata": {
      "durationMs": 6397.538499999995,
      "context": 22,
      "loop": 2,
      "model": "anthropic::2024-10-22::claude-3-5-haiku-latest"
    },
    "billingMetadata": {
      "product": "cody",
      "category": "billable"
    }
  },
  "timestamp": "2024-11-07T08:29:32.147Z"
}

Before

review loop took 14535.338709000032ms to complete 1 review loops

█ Autocomplete:onComplete duration:"3471ms" stopReason:"undefined" outputChannelId:"265a6f8d-d103-4b52-889b-b351503c5891": {
  "completion": "<TOOLSEARCH><query>convertGitCloneURLToCodebaseName</query></TOOLSEARCH>"
}
█ CodyTool searching codebase for convertGitCloneURLToCodebaseName:
█ Autocomplete:onComplete duration:"2105ms" stopReason:"undefined" outputChannelId:"78ba1f1e-3bb8-40be-92c4-34723b604efa": {
  "completion": "<keywords>\n<keyword>\n<value>git</value>\n<variants>git github gitlab bitbucket</variants>\n<weight>0.8</weight>\n</keyword>\n<keyword>\n<value>clone</value>\n<variants>clone cloning repository repo</variants>\n<weight>0.8</weight>\n</keyword>\n<keyword>\n<value>url</value>\n<variants>url link address</variants>\n<weight>0.7</weight>\n</keyword>\n<keyword>\n<value>convert</value>\n<variants>convert conversion transform</variants>\n<weight>0.9</weight>\n</keyword>\n<keyword>\n<value>codebase</value>\n<variants>codebase code repository project</variants>\n<weight>0.9</weight>\n</keyword>\n<keyword>\n<value>name</value>\n<variants>name identifier</variants>\n<weight>0.8</weight>\n</keyword>\n</keywords>"
}
█ Autocomplete:onComplete duration:"6086ms" stopReason:"undefined" outputChannelId:"2405087e-f5c8-40b7-967e-dd5f1a4ae011": {
  "completion": "CONTEXT_SUFFICIENT\n\nThe context provided reveals that the issue is in the `convertGitCloneURLToCodebaseName` function in `/lib/shared/src/utils.ts`, which currently does not handle SSH-style git URLs (like `[email protected]:...`) correctly.\n\nTo fix the issue, you'll need to modify the `convertGitCloneURLToCodebaseNameOrError` function to better handle SSH-style URLs. The existing code already has a regex match for SSH URLs, but it might need refinement to handle more complex URL formats.\n\nSpecifically, the current implementation should be updated to:\n1. Handle SSH URLs with different user prefixes\n2. Support URLs with ports\n3. Handle multiple subgroup/path components\n4. Ensure consistent parsing of `.git` suffix removal\n\nThe test cases in `/lib/shared/src/utils.test.ts` provide good examples of the URL formats that need to be supported."
}
█ telemetry-v2 recordEvent: cody.deep-cody.context/reviewed: {
  "parameters": {
    "version": 0,
    "metadata": [
      {
        "key": "tier",
        "value": 2
      }
    ],
    "privateMetadata": {
      "durationMs": 14535.338709000032,
      "context": 21,
      "loop": 1,
      "model": "anthropic::2024-10-22::claude-3-5-haiku-latest"
    },
    "billingMetadata": {
      "product": "cody",
      "category": "billable"
    }
  },
  "timestamp": "2024-11-07T08:08:19.987Z"
}

Example 2: " what models are available for dotcom users defined in the codebase?"

completion time: 10159.913833000232ms

image

█ Autocomplete:onComplete duration:"4173ms" stopReason:"undefined" outputChannelId:"67dee65c-2d3d-4b70-a11f-1a0f3988ba55": {
  "completion": "<TOOLSEARCH><query>available LLM models for dotcom users</query></TOOLSEARCH>"
}
█ CodyTool searching codebase for available LLM models for dotcom users:
█ Autocomplete:onComplete duration:"1156ms" stopReason:"undefined" outputChannelId:"c9a6f376-cfdb-4d26-a620-5e667a31c19b": {
  "completion": "<keywords>\n<keyword>\n<value>language models</value>\n<variants>LLM llm large language models</variants>\n<weight>0.9</weight>\n</keyword>\n<keyword>\n<value>web applications</value>\n<variants>dotcom web app webapp</variants>\n<weight>0.8</weight>\n</keyword>\n<keyword>\n<value>user documentation</value>\n<variants>user guide documentation</variants>\n<weight>0.7</weight>\n</keyword>\n</keywords>"
}
█ Autocomplete:onComplete duration:"2106ms" stopReason:"undefined" outputChannelId:"8c36152e-dbb1-4311-a9de-c498000ce509": {
  "completion": "<TOOLSEARCH><query>models available for dotcom users</query></TOOLSEARCH>"
}
█ CodyTool searching codebase for models available for dotcom users:
█ telemetry-v2 recordEvent: cody.deep-cody.context/reviewed: {
  "parameters": {
    "version": 0,
    "metadata": [
      {
        "key": "tier",
        "value": 2
      }
    ],
    "privateMetadata": {
      "durationMs": 10159.913833000232,
      "context": 42,
      "loop": 2,
      "model": "anthropic::2024-10-22::claude-3-5-haiku-latest"
    },
    "billingMetadata": {
      "product": "cody",
      "category": "billable"
    }
  },
  "timestamp": "2024-11-07T08:30:02.683Z"
}

Changelog

This change adds a `skipQueryRewrite` option to the `ContextRetriever.retrieveContext` method, which is used when retrieving context for the Search tool. This allows the Search tool to bypass the query rewriting step which make an extra LLM request, as the search query was already well-formatted from the review loop.

The `ContextRetriever._retrieveContext` method has been updated to handle the `skipQueryRewrite` option, and the `SearchTool` class now passes `true` for this option when calling `retrieveContext`.
@abeatrix abeatrix requested review from valerybugakov and a team November 7, 2024 08:43
Comment on lines 183 to +188
const context = await this.contextRetriever.retrieveContext(
toStructuredMentions([repo]),
PromptString.unsafe_fromLLMResponse(query),
span
span,
undefined,
true
Copy link
Member

Choose a reason for hiding this comment

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

For readability, let's use an object instead of an argument list here. Otherwise, it's unclear what undefined, true means without looking into the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I just read this after merging on my phone 😓 will do it in a follow up and tag you!

@PriNova
Copy link
Collaborator

PriNova commented Nov 7, 2024

@abeatrix I experience the same quality regression when using the Haiku model. Switching back to Sonnet 3.5 (new) is preferable.

@abeatrix abeatrix merged commit bc8b14e into main Nov 7, 2024
24 checks passed
@abeatrix abeatrix deleted the bee/deep-skip branch November 7, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants