test_retrieval_chunks.py


Overview

This file contains a suite of automated tests designed to validate the functionality of the retrieval_chunks API endpoint in the InfiniFlow system. The tests focus on verifying authorization, parameter handling, pagination, filtering, and concurrency aspects of chunk retrieval from datasets or documents.

The tests are implemented using the pytest framework and include multiple parameterized test cases to cover a wide range of inputs and expected outputs. This ensures robustness and correctness of the chunk retrieval API under different scenarios, including error handling for invalid inputs, and concurrent access.


Detailed Explanation

Imported Modules


Classes and Their Methods

TestAuthorization

Tests related to API authorization.

Methods


TestChunksRetrieval

Comprehensive tests for chunk retrieval functionality, including parameter validation and concurrency.

Common Parameters in Tests


Methods


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Usage Example

A typical test case flow in this file:

  1. Prepare a payload dictionary with parameters such as "question", "dataset_ids", "page", "page_size", etc.

  2. Obtain valid API authorization from a fixture.

  3. Call retrieval_chunks with the authorization and payload.

  4. Assert that the response's code, message, and returned chunk count match expected values.

def test_example(HttpApiAuth, add_chunks):
    dataset_id, _, _ = add_chunks
    payload = {"question": "example", "dataset_ids": [dataset_id], "page_size": 3}
    res = retrieval_chunks(HttpApiAuth, payload)
    assert res["code"] == 0
    assert len(res["data"]["chunks"]) == 3

Mermaid Diagram: Class Structure

classDiagram
    class TestAuthorization {
        +test_invalid_auth(invalid_auth, expected_code, expected_message)
    }
    class TestChunksRetrieval {
        +test_basic_scenarios(HttpApiAuth, add_chunks, payload, expected_code, expected_page_size, expected_message)
        +test_page(HttpApiAuth, add_chunks, payload, expected_code, expected_page_size, expected_message)
        +test_page_size(HttpApiAuth, add_chunks, payload, expected_code, expected_page_size, expected_message)
        +test_vector_similarity_weight(HttpApiAuth, add_chunks, payload, expected_code, expected_page_size, expected_message)
        +test_top_k(HttpApiAuth, add_chunks, payload, expected_code, expected_page_size, expected_message)
        +test_rerank_id(HttpApiAuth, add_chunks, payload, expected_code, expected_message)
        +test_keyword(HttpApiAuth, add_chunks, payload, expected_code, expected_page_size, expected_message)
        +test_highlight(HttpApiAuth, add_chunks, payload, expected_code, expected_highlight, expected_message)
        +test_invalid_params(HttpApiAuth, add_chunks)
        +test_concurrent_retrieval(HttpApiAuth, add_chunks)
    }

Summary