Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ def query_documents(
) -> list[dict[str, Any]]:
"""Run the minimal SDK query path used by the root CLI."""
retriever = Retriever(top_k=top_k, vdb_kwargs={"uri": lancedb_uri, "table_name": table_name})
return retriever.query(query)
hits = retriever.query(query)
hits = [{"text": hit.get("text", ""), "source": hit.get("source", ""), "page_number": hit.get("page_number")} for hit in hits]
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.

P1 The list comprehension on this line is ~130 characters, exceeding the project's enforced 120-character limit (Black + Flake8). The pre-commit hook will reject the file as-is, blocking CI. Black would reformat it to a multi-line style.

Suggested change
hits = [{"text": hit.get("text", ""), "source": hit.get("source", ""), "page_number": hit.get("page_number")} for hit in hits]
hits = [
{
"text": hit.get("text", ""),
"source": hit.get("source", ""),
"page_number": hit.get("page_number"),
}
for hit in hits
]
Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/adapters/cli/sdk_workflow.py
Line: 85

Comment:
The list comprehension on this line is ~130 characters, exceeding the project's enforced 120-character limit (Black + Flake8). The pre-commit hook will reject the file as-is, blocking CI. Black would reformat it to a multi-line style.

```suggestion
    hits = [
        {
            "text": hit.get("text", ""),
            "source": hit.get("source", ""),
            "page_number": hit.get("page_number"),
        }
        for hit in hits
    ]
```

How can I resolve this? If you propose a fix, please make it concise.

return hits
16 changes: 10 additions & 6 deletions nemo_retriever/tests/test_root_cli_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ def fail_create_ingestor(**_kwargs: Any) -> Any:
def test_root_query_passes_query_options_and_prints_json(monkeypatch) -> None:
retriever_calls: list[dict[str, Any]] = []
query_calls: list[str] = []
hits = [
{"text": "passage", "page_number": 1, "_distance": 0.2},
{"text": "other", "page_number": 2, "_distance": 0.4},
raw_hits = [
{"text": "passage", "source": "a.pdf", "page_number": 1, "_distance": 0.2},
{"text": "other", "source": "b.pdf", "page_number": 2, "_distance": 0.4},
]
# query_documents exposes only text / source / page_number (no scores or extra keys).
public_hits = [
{"text": h["text"], "source": h["source"], "page_number": h["page_number"]} for h in raw_hits
]

class FakeRetriever:
Expand All @@ -138,7 +142,7 @@ def __init__(self, **kwargs: Any) -> None:

def query(self, query: str) -> list[dict[str, Any]]:
query_calls.append(query)
return hits
return raw_hits

monkeypatch.setattr(sdk_workflow, "Retriever", FakeRetriever)

Expand All @@ -159,5 +163,5 @@ def query(self, query: str) -> list[dict[str, Any]]:
assert result.exit_code == 0
assert retriever_calls == [{"top_k": 3, "vdb_kwargs": {"uri": "/tmp/lancedb", "table_name": "docs"}}]
assert query_calls == ["Which animal is responsible for typos?"]
assert json.loads(result.output) == hits
assert result.output == json.dumps(hits, indent=2, sort_keys=True, default=str) + "\n"
assert json.loads(result.output) == public_hits
assert result.output == json.dumps(public_hits, indent=2, sort_keys=True, default=str) + "\n"
Loading