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
3 changes: 2 additions & 1 deletion src/codeweaver/providers/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class DocumentRepr:
async def serialize_for_upsert(self, texts: list[str]) -> list[Document]:
"""Serialize the document representations for Qdrant upsert."""
await asyncio.sleep(ZERO)
avg_length = int(sum(len(text.strip()) for text in texts) / len(texts)) if texts else 0
# Optimization: sum(map(len, map(str.strip, texts))) is significantly faster than a generator comprehension
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The inline note says “generator comprehension”, but the previous form was a generator expression (sum(len(text.strip()) for text in texts)). Using the correct term here will avoid confusion for readers.

Suggested change
# Optimization: sum(map(len, map(str.strip, texts))) is significantly faster than a generator comprehension
# Optimization: sum(map(len, map(str.strip, texts))) is significantly faster than a generator expression

Copilot uses AI. Check for mistakes.
avg_length = int(sum(map(len, map(str.strip, texts))) / len(texts)) if texts else 0
Comment on lines 136 to +138
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: The micro-optimization and use of float division may hurt readability with marginal benefit.

In this async, I/O-heavy path the performance gain is probably negligible compared to the readability cost. If you keep this form, you can simplify it to avoid float math and int() casting: avg_length = sum(map(len, map(str.strip, texts))) // len(texts). I’d also recommend softening or removing the “significantly faster” claim unless you have benchmarks to support it.

Suggested change
await asyncio.sleep(ZERO)
avg_length = int(sum(len(text.strip()) for text in texts) / len(texts)) if texts else 0
# Optimization: sum(map(len, map(str.strip, texts))) is significantly faster than a generator comprehension
avg_length = int(sum(map(len, map(str.strip, texts))) / len(texts)) if texts else 0
await asyncio.sleep(ZERO)
avg_length = (
sum(len(text.strip()) for text in texts) // len(texts)
if texts
else 0
)

options = await self.options.serialize_for_upsert(avg_length)
return [Document(text=text, model=self.model, options=options) for text in texts]

Expand Down
Loading