Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions src/pipelines/code_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from __future__ import annotations

import asyncio
import logging
from typing import Any, Callable, Dict, List, Optional

Expand Down Expand Up @@ -375,18 +376,24 @@ async def run(
turn_records: List[SourceRecord] = []
only_read_tools = True

for tc in ai_response.tool_calls:
async def _process_tool_call(tc):
tool_name = tc["name"]
tool_args = tc["args"]
tool_id = tc["id"]

t1 = _time.perf_counter()
records = await self._execute_tool(
tool_name, tool_args, repo=repo, top_k=top_k,
user_id=user_id,
)
tool_ms = (_time.perf_counter() - t1) * 1000
logger.info(" Tool: %s(%s) → %d results (%.0fms)", tool_name, tool_args, len(records), tool_ms)
return tc, records

results = await asyncio.gather(*(_process_tool_call(tc) for tc in ai_response.tool_calls))

for tc, records in results:
tool_name = tc["name"]
tool_id = tc["id"]

turn_records.extend(records)
sources.extend(records)

Expand Down Expand Up @@ -589,14 +596,19 @@ async def _search_symbols(
) -> List[SourceRecord]:
if not repo:
logger.warning("search_symbols called without repo — searching all repos")
results = []
for r in self.repos:
results.extend(await self._search_namespace(
all_results = await asyncio.gather(*(
self._search_namespace(
namespace=symbols_namespace(self.org_id, r),
query=query,
domain="symbol",
top_k=top_k,
))
)
for r in self.repos
))

results = []
for res in all_results:
results.extend(res)
return results[:top_k]

return await self._search_namespace(
Expand All @@ -612,14 +624,19 @@ async def _search_files(
self, query: str, repo: str, top_k: int = 10,
) -> List[SourceRecord]:
if not repo:
results = []
for r in self.repos:
results.extend(await self._search_namespace(
all_results = await asyncio.gather(*(
self._search_namespace(
namespace=files_namespace(self.org_id, r),
query=query,
domain="file",
top_k=top_k,
))
)
for r in self.repos
))

results = []
for res in all_results:
results.extend(res)
return results[:top_k]

return await self._search_namespace(
Expand Down
14 changes: 10 additions & 4 deletions src/pipelines/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from __future__ import annotations

import asyncio
import logging
import os
from typing import Any, Callable, Dict, List, Optional
Expand Down Expand Up @@ -177,16 +178,21 @@ async def run(

if ai_response.tool_calls:
called_tools = set()
for tc in ai_response.tool_calls:

async def _process_tool_call(tc):
tool_name = tc["name"]
tool_args = tc["args"]
tool_id = tc["id"]

logger.info(" Tool call: %s(%s)", tool_name, tool_args)

records = await self._execute_tool(
tool_name, tool_args, user_id, top_k,
)
return tc, records

results = await asyncio.gather(*(_process_tool_call(tc) for tc in ai_response.tool_calls))

for tc, records in results:
tool_name = tc["name"]
tool_id = tc["id"]
sources.extend(records)

# Build ToolMessage for the LLM
Expand Down