From 6855b04474ac99abfc82999558118d85e8a4c673 Mon Sep 17 00:00:00 2001 From: emrgnt-cmplxty Date: Fri, 13 Dec 2024 15:28:44 -0800 Subject: [PATCH] up --- .../actions/run-sdk-chunks-tests/action.yml | 53 ------- .../run-sdk-documents-tests/action.yml | 130 ------------------ .../r2r-full-integration-deep-dive-tests.yml | 41 ------ ...r2r-full-py-integration-tests-graphrag.yml | 67 --------- .../r2r-full-py-integration-tests.yml | 67 ++------- ...2r-light-py-integration-tests-graphrag.yml | 63 --------- .../r2r-light-py-integration-tests.yml | 49 +------ py/core/main/api/v3/graph_router.py | 20 +-- py/tests/integration/test_documents.py | 14 +- py/tests/integration/test_graphs.py | 27 +++- py/tests/integration/test_indices.py | 98 +++++++++++++ 11 files changed, 150 insertions(+), 479 deletions(-) delete mode 100644 .github/actions/run-sdk-chunks-tests/action.yml delete mode 100644 .github/actions/run-sdk-documents-tests/action.yml delete mode 100644 .github/workflows/r2r-full-integration-deep-dive-tests.yml delete mode 100644 .github/workflows/r2r-full-py-integration-tests-graphrag.yml delete mode 100644 .github/workflows/r2r-light-py-integration-tests-graphrag.yml create mode 100644 py/tests/integration/test_indices.py diff --git a/.github/actions/run-sdk-chunks-tests/action.yml b/.github/actions/run-sdk-chunks-tests/action.yml deleted file mode 100644 index a384c3eaf..000000000 --- a/.github/actions/run-sdk-chunks-tests/action.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: 'Run SDK Chunks Tests' -on: [push, pull_request] -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Install dependencies - run: | - pip install poetry - poetry install - - # Run the chunks tests - adjust order as needed - # This is similar to the documents tests, just calling different test functions - - - name: List chunks (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_list_chunks - - - name: Retrieve chunk (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_retrieve_chunk - - - name: Update chunk (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_update_chunk - - - name: Delete chunk (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_delete_chunk - - - name: Search chunks (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_search_chunks - - - name: List chunks with pagination (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_list_chunks_with_pagination - - - name: Retrieve chunk not found (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_retrieve_chunk_not_found - - - name: Unauthorized chunk access (SDK) - shell: bash - run: poetry run python tests/integration/runner_chunks.py test_unauthorized_chunk_access diff --git a/.github/actions/run-sdk-documents-tests/action.yml b/.github/actions/run-sdk-documents-tests/action.yml deleted file mode 100644 index e21bad64b..000000000 --- a/.github/actions/run-sdk-documents-tests/action.yml +++ /dev/null @@ -1,130 +0,0 @@ -name: 'Run SDK Ingestion Tests' -description: 'Runs extended SDK retrieval tests for R2R' -runs: - using: "composite" - steps: - - # Ingestion Variants - - name: Create document from file (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_create_document - - - name: Create document with raw_text (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_create_document_with_raw_text - - - name: Create document with chunks (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_create_document_with_chunks - - # Ingestion Modes - - name: Create document with different ingestion modes (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_create_document_different_modes - - # Listing and Pagination - - name: List documents (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_list_documents - - - name: List documents with pagination (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_list_documents_with_pagination - - - name: List document chunks (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_list_document_chunks - - # Retrieval and Download - - name: Retrieve document (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_retrieve_document - - - name: Download document (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_download_document - - # Collections - - name: List document collections (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_list_document_collections - - # Extraction & Searching - - name: Extract document (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_extract_document - - # ESTIMATES HAVE BEEN TURNED OFF FOR NOW - # - name: Extract document estimate (SDK) - # working-directory: ./py - # shell: bash - # run: poetry run python tests/integration/runner_documents.py test_extract_document_estimate - - - name: Search documents (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_search_documents - - - name: Extended search documents (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_search_documents_extended - - # Entities and Relationships - - name: List entities (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_list_entities - - - name: List relationships (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_list_relationships - - # Permission and Error Handling - - name: Extract document unauthorized (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_extract_document_unauthorized - - - name: Retrieve document not found (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_retrieve_document_not_found - - - name: Delete document non-existent (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_delete_document_non_existent - - - name: Get document collections non-superuser (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_get_document_collections_non_superuser - - - name: Access document not owned (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_access_document_not_owned - - # Deletions - - name: Delete document (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_delete_document - - - name: Delete document by filters (SDK) - working-directory: ./py - shell: bash - run: poetry run python tests/integration/runner_documents.py test_delete_document_by_filter diff --git a/.github/workflows/r2r-full-integration-deep-dive-tests.yml b/.github/workflows/r2r-full-integration-deep-dive-tests.yml deleted file mode 100644 index 9a4669885..000000000 --- a/.github/workflows/r2r-full-integration-deep-dive-tests.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: R2R Deep-Dive Integration Tests - -on: - push: - branches: - - dev - - dev-minor - - main - workflow_dispatch: - -jobs: - test: - runs-on: "ubuntu-latest" - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - AZURE_API_KEY: ${{ secrets.AZURE_API_KEY }} - AZURE_API_BASE: ${{ secrets.AZURE_API_BASE }} - AZURE_API_VERSION: ${{ secrets.AZURE_API_VERSION }} - TELEMETRY_ENABLED: 'false' - R2R_PROJECT_NAME: r2r_default - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python and install dependencies - uses: ./.github/actions/setup-python-full - with: - os: "ubuntu-latest" - - - name: Setup and start Docker - uses: ./.github/actions/setup-docker - - - name: Login Docker - uses: ./.github/actions/login-docker - with: - docker_username: ${{ secrets.RAGTORICHES_DOCKER_UNAME }} - docker_password: ${{ secrets.RAGTORICHES_DOCKER_TOKEN }} - - - name: Start R2R Full server - uses: ./.github/actions/start-r2r-full diff --git a/.github/workflows/r2r-full-py-integration-tests-graphrag.yml b/.github/workflows/r2r-full-py-integration-tests-graphrag.yml deleted file mode 100644 index f900bd3d7..000000000 --- a/.github/workflows/r2r-full-py-integration-tests-graphrag.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: R2R Full Python Integration Test (ubuntu) - -on: - push: - branches: - - main - pull_request: - branches: - - dev - - dev-minor - - main - workflow_dispatch: - -jobs: - test: - runs-on: ${{ matrix.os }} - continue-on-error: true - - strategy: - matrix: - os: [ubuntu-latest] - test_category: - - cli-graphrag - - sdk-graphrag - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - TELEMETRY_ENABLED: 'false' - R2R_PROJECT_NAME: r2r_default - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python and install dependencies - uses: ./.github/actions/setup-python-full - with: - os: ${{ matrix.os }} - - - name: Setup and start Docker - uses: ./.github/actions/setup-docker - - - name: Login Docker - uses: ./.github/actions/login-docker - with: - docker_username: ${{ secrets.RAGTORICHES_DOCKER_UNAME }} - docker_password: ${{ secrets.RAGTORICHES_DOCKER_TOKEN }} - - - name: Start R2R Full server - uses: ./.github/actions/start-r2r-full - - - name: Run CLI GraphRAG Tests - if: matrix.test_category == 'cli-graphrag' - uses: ./.github/actions/run-cli-graphrag-tests - - - name: Run SDK GraphRAG Tests - if: matrix.test_category == 'sdk-graphrag' - uses: ./.github/actions/run-sdk-graphrag-tests - - - name: Print Docker logs on failure - if: > - (matrix.test_category == 'cli-graphrag' && failure()) || - (matrix.test_category == 'sdk-graphrag' && failure()) - run: | - echo "::group::Docker Logs" - docker ps -a - docker logs r2r-full-r2r-1 - echo "::endgroup::" diff --git a/.github/workflows/r2r-full-py-integration-tests.yml b/.github/workflows/r2r-full-py-integration-tests.yml index b465edafd..6d98c211e 100644 --- a/.github/workflows/r2r-full-py-integration-tests.yml +++ b/.github/workflows/r2r-full-py-integration-tests.yml @@ -12,25 +12,15 @@ on: workflow_dispatch: jobs: - test: - runs-on: ${{ matrix.os }} - continue-on-error: true - - strategy: - matrix: - os: [ubuntu-latest] - test_category: - - cli-ingestion - - cli-retrieval - - sdk-ingestion - - sdk-retrieval - - sdk-auth - - sdk-collections - - sdk-prompts + integration-test: # or whatever name you want to give this job + runs-on: ubuntu-latest env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} TELEMETRY_ENABLED: 'false' R2R_PROJECT_NAME: r2r_default + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + AZURE_API_KEY: ${{ secrets.AZURE_API_KEY }} + AZURE_API_BASE: ${{ secrets.AZURE_API_BASE }} + AZURE_API_VERSION: ${{ secrets.AZURE_API_VERSION }} steps: - name: Checkout code @@ -38,8 +28,6 @@ jobs: - name: Set up Python and install dependencies uses: ./.github/actions/setup-python-full - with: - os: ${{ matrix.os }} - name: Setup and start Docker uses: ./.github/actions/setup-docker @@ -53,45 +41,6 @@ jobs: - name: Start R2R Full server uses: ./.github/actions/start-r2r-full - - name: Run CLI Ingestion Tests - if: matrix.test_category == 'cli-ingestion' - uses: ./.github/actions/run-cli-ingestion-tests - - - name: Run CLI Retrieval Tests - if: matrix.test_category == 'cli-retrieval' - uses: ./.github/actions/run-cli-retrieval-tests - - - name: Run SDK Ingestion Tests - if: matrix.test_category == 'sdk-ingestion' - uses: ./.github/actions/run-sdk-ingestion-tests - - - name: Run SDK Retrieval Tests - if: matrix.test_category == 'sdk-retrieval' - uses: ./.github/actions/run-sdk-retrieval-tests - - - name: Run SDK Auth Tests - if: matrix.test_category == 'sdk-auth' - uses: ./.github/actions/run-sdk-auth-tests - - - name: Run SDK Collections Tests - if: matrix.test_category == 'sdk-collections' - uses: ./.github/actions/run-sdk-collections-tests - - - name: Run SDK Prompt Tests - if: matrix.test_category == 'sdk-prompts' - uses: ./.github/actions/run-sdk-prompt-management-tests - - - name: Print Docker logs on failure - if: > - (matrix.test_category == 'cli-ingestion' && failure()) || - (matrix.test_category == 'sdk-ingestion' && failure()) || - (matrix.test_category == 'cli-retrieval' && failure()) || - (matrix.test_category == 'sdk-retrieval' && failure()) || - (matrix.test_category == 'sdk-auth' && failure()) || - (matrix.test_category == 'sdk-collections' && failure()) || - (matrix.test_category == 'sdk-prompts' && failure()) + - name: Run R2R Full Python Integration Test run: | - echo "::group::Docker Logs" - docker ps -a - docker logs r2r-full-r2r-1 - echo "::endgroup::" + python -m pytest diff --git a/.github/workflows/r2r-light-py-integration-tests-graphrag.yml b/.github/workflows/r2r-light-py-integration-tests-graphrag.yml deleted file mode 100644 index 44fa03603..000000000 --- a/.github/workflows/r2r-light-py-integration-tests-graphrag.yml +++ /dev/null @@ -1,63 +0,0 @@ -# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json - -name: R2R Light Python Integration Test (ubuntu) - -on: - push: - branches: - - main - pull_request: - branches: - - dev - - dev-minor - - main - workflow_dispatch: - -jobs: - test: - runs-on: ${{ matrix.os }} - continue-on-error: true - - strategy: - matrix: - os: [ubuntu-latest] - test_category: - - cli-graphrag - - sdk-graphrag - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - AZURE_API_KEY: ${{ secrets.AZURE_API_KEY }} - AZURE_API_BASE: ${{ secrets.AZURE_API_BASE }} - AZURE_API_VERSION: ${{ secrets.AZURE_API_VERSION }} - TELEMETRY_ENABLED: 'false' - R2R_POSTGRES_HOST: localhost - R2R_POSTGRES_DBNAME: postgres - R2R_POSTGRES_PORT: '5432' - R2R_POSTGRES_PASSWORD: postgres - R2R_POSTGRES_USER: postgres - R2R_PROJECT_NAME: r2r_default - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python and install dependencies - uses: ./.github/actions/setup-python-light - with: - os: ${{ matrix.os }} - - - name: Setup and start PostgreSQL - uses: ./.github/actions/setup-postgres-ext - with: - os: ${{ matrix.os }} - - - name: Start R2R Light server - uses: ./.github/actions/start-r2r-light - - - name: Run CLI GraphRAG Tests - if: matrix.test_category == 'cli-graphrag' - uses: ./.github/actions/run-cli-graphrag-tests - - - name: Run SDK GraphRAG Tests - if: matrix.test_category == 'sdk-graphrag' - uses: ./.github/actions/run-sdk-graphrag-tests diff --git a/.github/workflows/r2r-light-py-integration-tests.yml b/.github/workflows/r2r-light-py-integration-tests.yml index 656b8b38a..b287be43d 100644 --- a/.github/workflows/r2r-light-py-integration-tests.yml +++ b/.github/workflows/r2r-light-py-integration-tests.yml @@ -1,5 +1,3 @@ -# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json - name: R2R Light Python Integration Test (ubuntu) on: @@ -14,21 +12,8 @@ on: workflow_dispatch: jobs: - test: - runs-on: ${{ matrix.os }} - continue-on-error: true - - strategy: - matrix: - os: [ubuntu-latest] - test_category: - - cli-ingestion - - cli-retrieval - - sdk-ingestion - - sdk-retrieval - - sdk-auth - - sdk-collections - - sdk-prompts + integration-test: + runs-on: ubuntu-latest env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} AZURE_API_KEY: ${{ secrets.AZURE_API_KEY }} @@ -59,30 +44,6 @@ jobs: - name: Start R2R Light server uses: ./.github/actions/start-r2r-light - - name: Run CLI Ingestion Tests - if: matrix.test_category == 'cli-ingestion' - uses: ./.github/actions/run-cli-ingestion-tests - - - name: Run CLI Retrieval Tests - if: matrix.test_category == 'cli-retrieval' - uses: ./.github/actions/run-cli-retrieval-tests - - - name: Run SDK Ingestion Tests - if: matrix.test_category == 'sdk-ingestion' - uses: ./.github/actions/run-sdk-ingestion-tests - - - name: Run SDK Retrieval Tests - if: matrix.test_category == 'sdk-retrieval' - uses: ./.github/actions/run-sdk-retrieval-tests - - - name: Run SDK Auth Tests - if: matrix.test_category == 'sdk-auth' - uses: ./.github/actions/run-sdk-auth-tests - - - name: Run SDK Collections Tests - if: matrix.test_category == 'sdk-collections' - uses: ./.github/actions/run-sdk-collections-tests - - - name: Run SDK Prompt Tests - if: matrix.test_category == 'sdk-prompts' - uses: ./.github/actions/run-sdk-prompt-management-tests + - name: Run R2R Full Python Integration Test + run: | + python -m pytest diff --git a/py/core/main/api/v3/graph_router.py b/py/core/main/api/v3/graph_router.py index 5da73cb44..54e04e8dc 100644 --- a/py/core/main/api/v3/graph_router.py +++ b/py/core/main/api/v3/graph_router.py @@ -383,21 +383,13 @@ async def build_communities( server_graph_enrichment_settings, graph_enrichment_settings ) - # If the run type is estimate, return an estimate of the enrichment cost - # if run_type is KGRunType.ESTIMATE: - # return await self.services["kg"].get_enrichment_estimate( - # collection_id=id, - # graph_enrichment_settings=server_graph_enrichment_settings, - # ) - - # Otherwise, run the enrichment workflow - # else: + workflow_input = { + "collection_id": str(collection_id), + "graph_enrichment_settings": server_graph_enrichment_settings.model_dump_json(), + "user": auth_user.json(), + } + if run_with_orchestration: - workflow_input = { - "collection_id": str(collection_id), - "graph_enrichment_settings": server_graph_enrichment_settings.model_dump_json(), - "user": auth_user.json(), - } return await self.orchestration_provider.run_workflow( # type: ignore "build-communities", {"request": workflow_input}, {} diff --git a/py/tests/integration/test_documents.py b/py/tests/integration/test_documents.py index 1f2bb50d3..0b983a4c4 100644 --- a/py/tests/integration/test_documents.py +++ b/py/tests/integration/test_documents.py @@ -157,7 +157,7 @@ def test_delete_document_by_filter(client): ), "Document still exists after filter-based deletion" -@pytest.mark.skip(reason="Only if superuser-specific logic is implemented") +# @pytest.mark.skip(reason="Only if superuser-specific logic is implemented") def test_list_document_collections(client, test_document): # This test assumes the currently logged in user is a superuser collections = client.documents.list_collections(id=test_document)[ @@ -168,9 +168,9 @@ def test_list_document_collections(client, test_document): ), "Document collections list is not a list" -@pytest.mark.skip( - reason="Requires actual entity extraction logic implemented and superuser access" -) +# @pytest.mark.skip( +# reason="Requires actual entity extraction logic implemented and superuser access" +# ) def test_extract_document(client, test_document): run_resp = client.documents.extract( id=test_document, run_type="run", run_with_orchestration=False @@ -178,7 +178,7 @@ def test_extract_document(client, test_document): assert "message" in run_resp, "No message after extraction run" -@pytest.mark.skip(reason="Requires entity extraction results present") +# @pytest.mark.skip(reason="Requires entity extraction results present") def test_list_entities(client, test_document): # If no entities extracted yet, this could raise an exception try: @@ -189,7 +189,7 @@ def test_list_entities(client, test_document): pytest.skip(f"No entities extracted yet: {str(e)}") -@pytest.mark.skip(reason="Requires relationship extraction results present") +# @pytest.mark.skip(reason="Requires relationship extraction results present") def test_list_relationships(client, test_document): try: relationships = client.documents.list_relationships(id=test_document)[ @@ -260,7 +260,7 @@ def test_delete_document_non_existent(client): ), "Wrong error code for delete non-existent" -@pytest.mark.skip(reason="If your API restricts this endpoint to superusers") +# @pytest.mark.skip(reason="If your API restricts this endpoint to superusers") def test_get_document_collections_non_superuser(client): # Create a non-superuser client non_super_client = R2RClient(client.base_url) diff --git a/py/tests/integration/test_graphs.py b/py/tests/integration/test_graphs.py index e83150c0d..e6fc374c3 100644 --- a/py/tests/integration/test_graphs.py +++ b/py/tests/integration/test_graphs.py @@ -134,13 +134,38 @@ def test_create_and_get_relationship(client, test_collection): def test_build_communities(client, test_collection): collection_id = test_collection + + # Create two entities + entity1 = client.graphs.create_entity( + collection_id=collection_id, + name="Entity 1", + description="Entity 1 description", + )["results"] + entity2 = client.graphs.create_entity( + collection_id=collection_id, + name="Entity 2", + description="Entity 2 description", + )["results"] + + # Create relationship + rel_resp = client.graphs.create_relationship( + collection_id=collection_id, + subject="Entity 1", + subject_id=entity1["id"], + predicate="related_to", + object="Entity 2", + object_id=entity2["id"], + description="Test relationship", + )["results"] + relationship_id = rel_resp["id"] + # Build communities # Adjust parameters as needed if `run_type` and `settings` differ. # The router expects `run_type` and `graph_enrichment_settings`. resp = client.graphs.build( collection_id=collection_id, run_type="run", - graph_enrichment_settings={"use_semantic_clustering": True}, + # graph_enrichment_settings={"use_semantic_clustering": True}, run_with_orchestration=False, )["results"] diff --git a/py/tests/integration/test_indices.py b/py/tests/integration/test_indices.py new file mode 100644 index 000000000..8e0655902 --- /dev/null +++ b/py/tests/integration/test_indices.py @@ -0,0 +1,98 @@ +import uuid + +import pytest + +from r2r import R2RClient, R2RException + + +@pytest.fixture(scope="session") +def config(): + class TestConfig: + base_url = "http://localhost:7275" + superuser_email = "admin@example.com" + superuser_password = "change_me_immediately" + + return TestConfig() + + +@pytest.fixture(scope="session") +def client(config): + """Create a client instance and log in as superuser.""" + client = R2RClient(config.base_url) + client.users.login(config.superuser_email, config.superuser_password) + return client + + +def test_create_and_get_index(client): + index_name = f"test_index_{uuid.uuid4().hex[:8]}" + config = { + "table_name": "chunks", + "index_method": "hnsw", + "index_measure": "cosine_distance", + "index_arguments": {"m": 16, "ef_construction": 64, "ef": 40}, + "index_name": index_name, + "index_column": "vec", + "concurrently": True, + } + + # Create the index + create_resp = client.indices.create( + config=config, run_with_orchestration=True + )["results"] + assert "message" in create_resp, "No message in create response" + + # Get the index details + get_resp = client.indices.retrieve( + index_name=index_name, table_name="chunks" + )["results"] + assert "index" in get_resp, "No index in get response" + assert get_resp["index"]["name"] == index_name, "Index name mismatch" + + +def test_list_indices(client): + resp = client.indices.list(limit=5)["results"] + assert "indices" in resp, "No indices field in response" + # Just ensure we get a list without error. Detailed checks depend on data availability. + assert isinstance(resp["indices"], list), "Indices field is not a list" + + +def test_delete_index(client): + # Create an index to delete + index_name = f"test_delete_index_{uuid.uuid4().hex[:8]}" + config = { + "table_name": "chunks", + "index_method": "hnsw", + "index_measure": "cosine_distance", + "index_arguments": {"m": 16, "ef_construction": 64, "ef": 40}, + "index_name": index_name, + "index_column": "vec", + "concurrently": True, + } + + client.indices.create(config=config, run_with_orchestration=True)[ + "results" + ] + + # Delete the index + delete_resp = client.indices.delete( + index_name=index_name, table_name="chunks" + )["results"] + assert "message" in delete_resp, "No message in delete response" + + # Verify deletion by attempting to retrieve the index + with pytest.raises(R2RException) as exc_info: + client.indices.retrieve(index_name=index_name, table_name="chunks") + assert ( + "not found" in str(exc_info.value).lower() + ), "Unexpected error message for deleted index" + + +def test_error_handling(client): + # Try to get a non-existent index + with pytest.raises(R2RException) as exc_info: + client.indices.retrieve( + index_name="nonexistent_index", table_name="chunks" + ) + assert ( + "not found" in str(exc_info.value).lower() + ), "Unexpected error message for non-existent index"