correctly filter by folder in codebase retrieval
This commit is contained in:
parent
c0ba66e955
commit
eb0fb82dc2
4 changed files with 36 additions and 12 deletions
|
|
@ -5,7 +5,7 @@ import BaseRetrievalPipeline from "./BaseRetrievalPipeline.js";
|
|||
|
||||
export default class NoRerankerRetrievalPipeline extends BaseRetrievalPipeline {
|
||||
async run(): Promise<Chunk[]> {
|
||||
const { input, nFinal } = this.options;
|
||||
const { input, nFinal, filterDirectory } = this.options;
|
||||
|
||||
// We give 1/4 weight to recently edited files, 1/4 to full text search,
|
||||
// and the remaining 1/2 to embeddings
|
||||
|
|
@ -13,7 +13,7 @@ export default class NoRerankerRetrievalPipeline extends BaseRetrievalPipeline {
|
|||
const ftsNFinal = nFinal * 0.25;
|
||||
const embeddingsNFinal = nFinal - recentlyEditedNFinal - ftsNFinal;
|
||||
|
||||
const retrievalResults: Chunk[] = [];
|
||||
let retrievalResults: Chunk[] = [];
|
||||
|
||||
const ftsChunks = await this.retrieveFts(input, ftsNFinal);
|
||||
|
||||
|
|
@ -30,6 +30,7 @@ export default class NoRerankerRetrievalPipeline extends BaseRetrievalPipeline {
|
|||
this.options.config,
|
||||
this.options.ide,
|
||||
input,
|
||||
filterDirectory,
|
||||
);
|
||||
|
||||
retrievalResults.push(
|
||||
|
|
@ -39,6 +40,13 @@ export default class NoRerankerRetrievalPipeline extends BaseRetrievalPipeline {
|
|||
...repoMapChunks,
|
||||
);
|
||||
|
||||
if (filterDirectory) {
|
||||
// Backup if the individual retrieval methods don't listen
|
||||
retrievalResults = retrievalResults.filter((chunk) =>
|
||||
chunk.filepath.startsWith(filterDirectory),
|
||||
);
|
||||
}
|
||||
|
||||
const deduplicatedRetrievalResults: Chunk[] =
|
||||
deduplicateChunks(retrievalResults);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import BaseRetrievalPipeline from "./BaseRetrievalPipeline.js";
|
|||
|
||||
export default class RerankerRetrievalPipeline extends BaseRetrievalPipeline {
|
||||
private async _retrieveInitial(): Promise<Chunk[]> {
|
||||
const { input, nRetrieve } = this.options;
|
||||
const { input, nRetrieve, filterDirectory } = this.options;
|
||||
|
||||
const retrievalResults: Chunk[] = [];
|
||||
let retrievalResults: Chunk[] = [];
|
||||
|
||||
const ftsChunks = await this.retrieveFts(input, nRetrieve);
|
||||
const embeddingsChunks = await this.retrieveEmbeddings(input, nRetrieve);
|
||||
|
|
@ -20,6 +20,7 @@ export default class RerankerRetrievalPipeline extends BaseRetrievalPipeline {
|
|||
this.options.config,
|
||||
this.options.ide,
|
||||
input,
|
||||
filterDirectory,
|
||||
);
|
||||
|
||||
retrievalResults.push(
|
||||
|
|
@ -29,6 +30,13 @@ export default class RerankerRetrievalPipeline extends BaseRetrievalPipeline {
|
|||
...repoMapChunks,
|
||||
);
|
||||
|
||||
if (filterDirectory) {
|
||||
// Backup if the individual retrieval methods don't listen
|
||||
retrievalResults = retrievalResults.filter((chunk) =>
|
||||
chunk.filepath.startsWith(filterDirectory),
|
||||
);
|
||||
}
|
||||
|
||||
const deduplicatedRetrievalResults: Chunk[] =
|
||||
deduplicateChunks(retrievalResults);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export async function requestFilesFromRepoMap(
|
|||
config: ContinueConfig,
|
||||
ide: IDE,
|
||||
input: string,
|
||||
filterDirectory?: string,
|
||||
): Promise<Chunk[]> {
|
||||
const llm =
|
||||
config.models.find(
|
||||
|
|
@ -20,7 +21,10 @@ export async function requestFilesFromRepoMap(
|
|||
}
|
||||
|
||||
try {
|
||||
const repoMap = await generateRepoMap(llm, ide, { signatures: false });
|
||||
const repoMap = await generateRepoMap(llm, ide, {
|
||||
signatures: false,
|
||||
dirs: filterDirectory ? [filterDirectory] : undefined,
|
||||
});
|
||||
|
||||
const prompt = `${repoMap}
|
||||
|
||||
|
|
@ -41,13 +45,16 @@ This is the question that you should select relevant files for: "${input}"`;
|
|||
return [];
|
||||
}
|
||||
|
||||
const pathSep = await ide.pathSep();
|
||||
const subDirPrefix = filterDirectory ? filterDirectory + pathSep : "";
|
||||
const files =
|
||||
content
|
||||
.split("<results>")[1]
|
||||
?.split("</results>")[0]
|
||||
?.split("\n")
|
||||
.filter(Boolean)
|
||||
.map((file) => file.trim()) ?? [];
|
||||
.map((file) => file.trim())
|
||||
.map((file) => subDirPrefix + file) ?? [];
|
||||
|
||||
const chunks = await Promise.all(
|
||||
files.map(async (file) => {
|
||||
|
|
|
|||
|
|
@ -24,17 +24,18 @@ function indentMultilineString(str: string) {
|
|||
|
||||
export interface RepoMapOptions {
|
||||
signatures?: boolean;
|
||||
dirs?: string[];
|
||||
}
|
||||
|
||||
async function generateRepoMap(llm: ILLM, ide: IDE, options?: RepoMapOptions) {
|
||||
const repoMapPath = getRepoMapFilePath();
|
||||
const workspaceDirs = await ide.getWorkspaceDirs();
|
||||
const dirs = options?.dirs ?? (await ide.getWorkspaceDirs());
|
||||
const maxRepoMapTokens = llm.contextLength * REPO_MAX_CONTEXT_LENGTH_RATIO;
|
||||
|
||||
const pathsWithoutSnippets = new Set<string>();
|
||||
for (const workspaceDir of workspaceDirs) {
|
||||
for await (const filepath of walkDirAsync(workspaceDir, ide)) {
|
||||
pathsWithoutSnippets.add(filepath.replace(workspaceDir, "").slice(1));
|
||||
for (const dir of dirs) {
|
||||
for await (const filepath of walkDirAsync(dir, ide)) {
|
||||
pathsWithoutSnippets.add(filepath.replace(dir, "").slice(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ async function generateRepoMap(llm: ILLM, ide: IDE, options?: RepoMapOptions) {
|
|||
while (true) {
|
||||
const { groupedByPath, hasMore } =
|
||||
await CodeSnippetsCodebaseIndex.getPathsAndSignatures(
|
||||
workspaceDirs,
|
||||
dirs,
|
||||
offset,
|
||||
batchSize,
|
||||
);
|
||||
|
|
@ -61,7 +62,7 @@ async function generateRepoMap(llm: ILLM, ide: IDE, options?: RepoMapOptions) {
|
|||
|
||||
for (const [absolutePath, signatures] of Object.entries(groupedByPath)) {
|
||||
const workspaceDir =
|
||||
workspaceDirs.find((dir) => absolutePath.startsWith(dir)) || "";
|
||||
dirs.find((dir) => absolutePath.startsWith(dir)) || "";
|
||||
|
||||
const relativePath = path.relative(workspaceDir, absolutePath);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue