Skip to content
Open
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
16 changes: 12 additions & 4 deletions refactron/rag/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(
self.parser = CodeParser()

def index_repository(
self, repo_path: Optional[Path] = None, summarize: bool = False
self, repo_path: Optional[Path] = None, summarize: bool = False, batch_size: int = 100
) -> IndexStats:
"""Index an entire repository.

Expand Down Expand Up @@ -127,6 +127,8 @@ def index_repository(

total_chunks = 0
chunk_type_counts: Dict[str, int] = {}

current_batch: List[CodeChunk] = []

# Index each file
for py_file in python_files:
Expand All @@ -139,11 +141,20 @@ def index_repository(
chunk_type_counts[chunk.chunk_type] = (
chunk_type_counts.get(chunk.chunk_type, 0) + 1
)

current_batch.extend(chunks)

if len(current_batch) >= batch_size:
self.add_chunks(current_batch)
current_batch = []
except Exception as e:
# Skip files that can't be parsed
print(f"Warning: Could not index {py_file}: {e}")
continue

if current_batch:
self.add_chunks(current_batch)

# Save index metadata
self._save_metadata(
{
Expand Down Expand Up @@ -188,9 +199,6 @@ def _index_file(self, file_path: Path, summarize: bool = False) -> List[CodeChun
except Exception as e:
print(f"Warning: AI summarization failed for chunk in {file_path}: {e}")

# Add chunks to the index
self.add_chunks(chunks)

return chunks

def _summarize_chunk(self, chunk: CodeChunk) -> Optional[str]:
Expand Down
Loading