test_invoke_with_k_kwarg() — langchain Function Reference
Architecture documentation for the test_invoke_with_k_kwarg() function in retrievers.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d2c2c5dd_4f95_a639_ec1d_0d837291f8ad["test_invoke_with_k_kwarg()"] 832b9ba1_75e8_ad0c_71b4_3f5c6d4c0825["RetrieversIntegrationTests"] d2c2c5dd_4f95_a639_ec1d_0d837291f8ad -->|defined in| 832b9ba1_75e8_ad0c_71b4_3f5c6d4c0825 style d2c2c5dd_4f95_a639_ec1d_0d837291f8ad fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/retrievers.py lines 102–151
def test_invoke_with_k_kwarg(self, retriever: BaseRetriever) -> None:
"""Test the number of results parameter in `invoke`.
Test that the invoke method accepts a parameter representing
the number of documents to return.
By default, the parameter is named, but it can be overridden by
setting the `num_results_arg_name` property.
!!! note
If the retriever doesn't support configuring the number of results returned
via the invoke method, this test can be skipped using a pytest `xfail` on
the test class:
```python
@pytest.mark.xfail(
reason="This retriever doesn't support setting "
"the number of results in the invoke method."
)
def test_invoke_with_k_kwarg(self) -> None:
raise NotImplementedError
```
??? note "Troubleshooting"
If this test fails, the retriever's invoke method does not accept a number
of results parameter, or the retriever does not return the correct number
of documents (`k` of the one set in `num_results_arg_name`) when it is
set.
For example, a retriever like...
```python
MyRetriever().invoke("query", k=3)
```
...should return 3 documents when invoked with a query.
"""
result_1 = retriever.invoke(
self.retriever_query_example, None, **{self.num_results_arg_name: 1}
)
assert len(result_1) == 1
assert all(isinstance(doc, Document) for doc in result_1)
result_3 = retriever.invoke(
self.retriever_query_example, None, **{self.num_results_arg_name: 3}
)
assert len(result_3) == 3
assert all(isinstance(doc, Document) for doc in result_3)
Domain
Subdomains
Source
Frequently Asked Questions
What does test_invoke_with_k_kwarg() do?
test_invoke_with_k_kwarg() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/retrievers.py.
Where is test_invoke_with_k_kwarg() defined?
test_invoke_with_k_kwarg() is defined in libs/standard-tests/langchain_tests/integration_tests/retrievers.py at line 102.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free