Skip to content

Commit

Permalink
fix(amazonq): update cross file context config #4922
Browse files Browse the repository at this point in the history
- number of input chunks for BM25 retrieval needs to be changed from 60 to 200,
- the chunk size is changed from 10 lines to 50 lines, which means totally 200x 50 lines of cross-file code will be considered in the BM25 retrieval.
- number of chunks returned from plugin to server for prompting increased from 3 to 10.
  • Loading branch information
leigaol committed May 3, 2024
1 parent eca2efe commit e6d9b50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Update cross file context config for Q inline suggestion"
}
6 changes: 3 additions & 3 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ export const codeFixAppliedFailedMessage = 'Failed to apply suggested code fix.'
export const runSecurityScanButtonTitle = 'Run security scan'

export const crossFileContextConfig = {
numberOfChunkToFetch: 60,
topK: 3,
numberOfLinesEachChunk: 10,
numberOfChunkToFetch: 200,
topK: 10,
numberOfLinesEachChunk: 50,
}

export const utgConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,30 @@ describe('crossFileContextUtil', function () {
tempFolder = (await createTestWorkspaceFolder()).uri.fsPath
})

describe('should fetch 3 chunks and each chunk should contains 10 lines', function () {
describe('should fetch 10 chunks and each chunk should contains 50 lines', function () {
async function assertCorrectCodeChunk() {
await openATextEditorWithText(sampleFileOf60Lines, 'CrossFile.java', tempFolder, { preview: false })
await openATextEditorWithText(sampleFileOf60Lines.repeat(10), 'CrossFile.java', tempFolder, {
preview: false,
})
const myCurrentEditor = await openATextEditorWithText('', 'TargetFile.java', tempFolder, {
preview: false,
})
const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken)
assert.ok(actual)
assert.ok(actual.supplementalContextItems.length === 3)

assert.strictEqual(actual.supplementalContextItems[0].content.split('\n').length, 10)
assert.strictEqual(actual.supplementalContextItems[1].content.split('\n').length, 10)
assert.strictEqual(actual.supplementalContextItems[2].content.split('\n').length, 10)
assert.ok(actual.supplementalContextItems.length === crossFileContextConfig.topK)

assert.strictEqual(
actual.supplementalContextItems[0].content.split('\n').length,
crossFileContextConfig.numberOfLinesEachChunk
)
assert.strictEqual(
actual.supplementalContextItems[1].content.split('\n').length,
crossFileContextConfig.numberOfLinesEachChunk
)
assert.strictEqual(
actual.supplementalContextItems[2].content.split('\n').length,
crossFileContextConfig.numberOfLinesEachChunk
)
}

it('control group', async function () {
Expand Down Expand Up @@ -267,12 +278,12 @@ describe('crossFileContextUtil', function () {
assert.strictEqual(chunks[1].content, 'line_6\nline_7')
})

it('codewhisperer crossfile config should use 10 lines', async function () {
it('codewhisperer crossfile config should use 50 lines', async function () {
const filePath = path.join(tempFolder, 'file.txt')
await toFile(sampleFileOf60Lines, filePath)

const chunks = await crossFile.splitFileToChunks(filePath, crossFileContextConfig.numberOfLinesEachChunk)
assert.strictEqual(chunks.length, 6)
assert.strictEqual(chunks.length, 2)
})
})
})
Expand Down

0 comments on commit e6d9b50

Please sign in to comment.