You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "yanchaomei (via GitHub)" <gi...@apache.org> on 2025/03/05 09:35:35 UTC

[PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

yanchaomei opened a new pull request, #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192

   fix #167
   
   # Comprehensive Test Suite Implementation for HugeGraph-LLM
   
   This PR implements a complete test suite for the HugeGraph-LLM project, covering all major components and ensuring code quality and reliability.
   
   ## Summary of Test Implementation
   
   ### 1. Test Infrastructure
   - Created `run_tests.py` script for easy test execution
   - Implemented `conftest.py` with test configuration and fixtures
   - Added test utilities in `test_utils.py` for common testing functions
   - Set up test data directories with sample documents, schemas, and prompts
   
   ### 2. Document Processing Tests
   - `test_document.py`: Tests for document module imports and basic functionality
   - `test_document_splitter.py`: Tests for document chunking in different languages
   - `test_text_loader.py`: Tests for loading text files with various encodings
   
   ### 3. Integration Tests
   - `test_graph_rag_pipeline.py`: End-to-end tests for graph-based RAG pipeline
   - `test_kg_construction.py`: Tests for knowledge graph construction from documents
   - `test_rag_pipeline.py`: Tests for standard RAG pipeline functionality
   
   ### 4. Middleware Tests
   - `test_middleware.py`: Tests for FastAPI middleware components
   
   ### 5. Model Tests
   - LLM Tests:
     - `test_openai_client.py`: Tests for OpenAI API integration
     - `test_qianfan_client.py`: Tests for Baidu Qianfan API integration
     - `test_ollama_client.py`: Tests for Ollama local model integration
   - Embedding Tests:
     - `test_openai_embedding.py`: Tests for OpenAI embedding functionality
     - `test_ollama_embedding.py`: Tests for Ollama embedding functionality
   - Reranker Tests:
     - `test_cohere_reranker.py`: Tests for Cohere reranking API
     - `test_siliconflow_reranker.py`: Tests for SiliconFlow reranking API
     - `test_init_reranker.py`: Tests for reranker initialization
   
   ### 6. Operator Tests
   - Common Operations:
     - `test_check_schema.py`: Tests for schema validation
     - `test_merge_dedup_rerank.py`: Tests for result merging and reranking
     - `test_nltk_helper.py`: Tests for NLP utilities
     - `test_print_result.py`: Tests for result output formatting
   - Document Operations:
     - `test_chunk_split.py`: Tests for document chunking strategies
     - `test_word_extract.py`: Tests for keyword extraction
   - HugeGraph Operations:
     - `test_commit_to_hugegraph.py`: Tests for graph data writing
     - `test_fetch_graph_data.py`: Tests for graph data retrieval
     - `test_graph_rag_query.py`: Tests for graph-based RAG queries
     - `test_schema_manager.py`: Tests for graph schema management
   - Index Operations:
     - `test_build_gremlin_example_index.py`: Tests for Gremlin example indexing
     - `test_build_semantic_index.py`: Tests for semantic indexing
     - `test_build_vector_index.py`: Tests for vector index construction
     - `test_gremlin_example_index_query.py`: Tests for querying Gremlin examples
     - `test_semantic_id_query.py`: Tests for semantic ID queries
     - `test_vector_index_query.py`: Tests for vector index queries
   - LLM Operations:
     - `test_gremlin_generate.py`: Tests for Gremlin query generation
     - `test_keyword_extract.py`: Tests for LLM-based keyword extraction
     - `test_property_graph_extract.py`: Tests for property graph extraction
   
   ## Testing Approach
   
   The test suite employs several testing strategies:
   
   1. **Unit Tests**: Testing individual components in isolation
   2. **Integration Tests**: Testing interactions between components
   3. **Mock Testing**: Using mocks to simulate external dependencies
   4. **Parametrized Tests**: Testing with various input combinations
   5. **Exception Testing**: Verifying proper error handling
   
   ## Key Features
   
   - **Comprehensive Coverage**: Tests for all major modules and components
   - **External Service Handling**: Tests can skip external service dependencies when needed
   - **Mock Implementations**: Provides mock implementations for external services
   - **Test Data**: Includes sample data for consistent test execution
   - **Isolation**: Tests are designed to run independently without side effects
   
   ## Results
   
   All tests pass successfully, ensuring the reliability and correctness of the HugeGraph-LLM codebase. The test suite provides a solid foundation for future development and helps maintain code quality as the project evolves.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192#discussion_r1982870274


##########
.github/workflows/hugegraph-llm.yml:
##########
@@ -0,0 +1,70 @@
+name: HugeGraph-LLM CI
+
+on:
+  push:
+    branches:
+      - 'release-*'
+  pull_request:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        python-version: ["3.9", "3.10", "3.11", "3.12"]
+
+    steps:
+    - name: Prepare HugeGraph Server Environment
+      run: |
+        docker run -d --name=graph -p 8080:8080 -e PASSWORD=admin hugegraph/hugegraph:1.3.0
+        sleep 10
+
+    - uses: actions/checkout@v4
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v5
+      with:
+        python-version: ${{ matrix.python-version }}
+
+    - name: Install uv
+      run: |
+        curl -LsSf https://astral.sh/uv/install.sh | sh
+        echo "$HOME/.cargo/bin" >> $GITHUB_PATH
+
+    - name: Cache dependencies
+      id: cache-deps
+      uses: actions/cache@v4
+      with:
+        path: |
+          .venv
+          ~/.cache/uv
+          ~/.cache/pip
+        key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('hugegraph-llm/requirements.txt') }}
+        restore-keys: |
+          ${{ runner.os }}-venv-${{ matrix.python-version }}-
+          ${{ runner.os }}-venv-
+
+    - name: Install dependencies
+      if: steps.cache-deps.outputs.cache-hit != 'true'
+      run: |
+        uv venv
+        source .venv/bin/activate
+        uv pip install pytest pytest-cov
+        uv pip install -r ./hugegraph-llm/requirements.txt
+
+    - name: Run unit tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/operators/hugegraph_op/ src/tests/config/ src/tests/document/ src/tests/middleware/ -v
+
+    - name: Run integration tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/integration/test_graph_rag_pipeline.py -v

Review Comment:
   Note each file should have a EOF line  (U could config it in your IDE's settings)
   
   <img width="605" alt="image" src="https://github.com/user-attachments/assets/52eadd13-c551-46b1-aa33-d4d4ac5186c8" />
   



##########
.github/workflows/hugegraph-llm.yml:
##########
@@ -0,0 +1,70 @@
+name: HugeGraph-LLM CI
+
+on:
+  push:
+    branches:
+      - 'release-*'
+  pull_request:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        python-version: ["3.9", "3.10", "3.11", "3.12"]
+
+    steps:
+    - name: Prepare HugeGraph Server Environment
+      run: |
+        docker run -d --name=graph -p 8080:8080 -e PASSWORD=admin hugegraph/hugegraph:1.3.0
+        sleep 10
+
+    - uses: actions/checkout@v4
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v5
+      with:
+        python-version: ${{ matrix.python-version }}
+
+    - name: Install uv
+      run: |
+        curl -LsSf https://astral.sh/uv/install.sh | sh
+        echo "$HOME/.cargo/bin" >> $GITHUB_PATH
+
+    - name: Cache dependencies
+      id: cache-deps
+      uses: actions/cache@v4
+      with:
+        path: |
+          .venv
+          ~/.cache/uv
+          ~/.cache/pip
+        key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('hugegraph-llm/requirements.txt') }}
+        restore-keys: |
+          ${{ runner.os }}-venv-${{ matrix.python-version }}-
+          ${{ runner.os }}-venv-
+
+    - name: Install dependencies
+      if: steps.cache-deps.outputs.cache-hit != 'true'
+      run: |
+        uv venv
+        source .venv/bin/activate
+        uv pip install pytest pytest-cov
+        uv pip install -r ./hugegraph-llm/requirements.txt
+
+    - name: Run unit tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/operators/hugegraph_op/ src/tests/config/ src/tests/document/ src/tests/middleware/ -v
+
+    - name: Run integration tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/integration/test_graph_rag_pipeline.py -v

Review Comment:
   Note each file should have a EOF line  (U could config it in your IDE's settings)
   
   <img width="605" alt="image" src="https://github.com/user-attachments/assets/52eadd13-c551-46b1-aa33-d4d4ac5186c8" />
   
   So as others files



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192#discussion_r1982875285


##########
.github/workflows/hugegraph-llm.yml:
##########
@@ -0,0 +1,70 @@
+name: HugeGraph-LLM CI
+
+on:
+  push:
+    branches:
+      - 'release-*'
+  pull_request:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        python-version: ["3.9", "3.10", "3.11", "3.12"]
+
+    steps:
+    - name: Prepare HugeGraph Server Environment
+      run: |
+        docker run -d --name=graph -p 8080:8080 -e PASSWORD=admin hugegraph/hugegraph:1.3.0
+        sleep 10
+
+    - uses: actions/checkout@v4
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v5
+      with:
+        python-version: ${{ matrix.python-version }}
+
+    - name: Install uv
+      run: |
+        curl -LsSf https://astral.sh/uv/install.sh | sh
+        echo "$HOME/.cargo/bin" >> $GITHUB_PATH
+
+    - name: Cache dependencies
+      id: cache-deps
+      uses: actions/cache@v4
+      with:
+        path: |
+          .venv
+          ~/.cache/uv
+          ~/.cache/pip
+        key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('hugegraph-llm/requirements.txt') }}
+        restore-keys: |
+          ${{ runner.os }}-venv-${{ matrix.python-version }}-
+          ${{ runner.os }}-venv-
+
+    - name: Install dependencies
+      if: steps.cache-deps.outputs.cache-hit != 'true'
+      run: |
+        uv venv
+        source .venv/bin/activate
+        uv pip install pytest pytest-cov
+        uv pip install -r ./hugegraph-llm/requirements.txt
+
+    - name: Run unit tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/operators/hugegraph_op/ src/tests/config/ src/tests/document/ src/tests/middleware/ -v
+
+    - name: Run integration tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/integration/test_graph_rag_pipeline.py -v

Review Comment:
   https://github.com/apache/incubator-hugegraph-ai/actions/runs/13693587346/job/38291894859?pr=192
   
   And could check the CI status here (U could submit a PR in your own repo, select the upstream branch like
   `yanchaomei:main` to test it separately)
   
   <img width="754" alt="image" src="https://github.com/user-attachments/assets/00d6ba4d-f32c-4051-95d1-a68c2162b851" />
   
   Also better not use `main/master` as your default branch, keep it clean & it could sync the code with upstream 
    easily(one-click), if u want to modify some code u could checkout a **new branch** from `main` like `dev-xx` (This can avoid many potential conflicts and inconsistencies in the future, and also maintain clarity in using Git)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192#discussion_r1981156314


##########
hugegraph-llm/run_tests.py:
##########
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3

Review Comment:
   Also we should enable the test in the related CI file: 
   like add a `.github/workflows/graph_rag.yml` ?
   
   could refer: https://github.com/apache/incubator-hugegraph-ai/blob/ca28faf29b1d3499467cc8b366b4462b829182e5/.github/workflows/hugegraph-python-client.yml#L66



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "yanchaomei (via GitHub)" <gi...@apache.org>.
yanchaomei commented on code in PR #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192#discussion_r1981456699


##########
hugegraph-llm/run_tests.py:
##########
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3

Review Comment:
   get it~ I will do it soon



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192#discussion_r1981144600


##########
hugegraph-llm/run_tests.py:
##########
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3

Review Comment:
   seems we don't need it? 
   
   Also check other CI check, THX~



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192#discussion_r1982875285


##########
.github/workflows/hugegraph-llm.yml:
##########
@@ -0,0 +1,70 @@
+name: HugeGraph-LLM CI
+
+on:
+  push:
+    branches:
+      - 'release-*'
+  pull_request:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        python-version: ["3.9", "3.10", "3.11", "3.12"]
+
+    steps:
+    - name: Prepare HugeGraph Server Environment
+      run: |
+        docker run -d --name=graph -p 8080:8080 -e PASSWORD=admin hugegraph/hugegraph:1.3.0
+        sleep 10
+
+    - uses: actions/checkout@v4
+
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v5
+      with:
+        python-version: ${{ matrix.python-version }}
+
+    - name: Install uv
+      run: |
+        curl -LsSf https://astral.sh/uv/install.sh | sh
+        echo "$HOME/.cargo/bin" >> $GITHUB_PATH
+
+    - name: Cache dependencies
+      id: cache-deps
+      uses: actions/cache@v4
+      with:
+        path: |
+          .venv
+          ~/.cache/uv
+          ~/.cache/pip
+        key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('hugegraph-llm/requirements.txt') }}
+        restore-keys: |
+          ${{ runner.os }}-venv-${{ matrix.python-version }}-
+          ${{ runner.os }}-venv-
+
+    - name: Install dependencies
+      if: steps.cache-deps.outputs.cache-hit != 'true'
+      run: |
+        uv venv
+        source .venv/bin/activate
+        uv pip install pytest pytest-cov
+        uv pip install -r ./hugegraph-llm/requirements.txt
+
+    - name: Run unit tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/operators/hugegraph_op/ src/tests/config/ src/tests/document/ src/tests/middleware/ -v
+
+    - name: Run integration tests
+      run: |
+        source .venv/bin/activate
+        export PYTHONPATH=$(pwd)/hugegraph-llm/src
+        export SKIP_EXTERNAL_SERVICES=true
+        cd hugegraph-llm
+        python -m pytest src/tests/integration/test_graph_rag_pipeline.py -v

Review Comment:
   https://github.com/apache/incubator-hugegraph-ai/actions/runs/13693587346/job/38291894859?pr=192
   
   And could check the CI status here (U could submit a PR in your own repo, select the upstream branch like
   `yanchaomei:main` to test it separately)
   
   <img width="754" alt="image" src="https://github.com/user-attachments/assets/00d6ba4d-f32c-4051-95d1-a68c2162b851" />
   
   Also better not use `main/master` as your default branch, keep it clean & sync the code with upstream branches, if u want to modify some code u could checkout a new branch from `main` like `dev-xx` (This can avoid many potential conflicts and inconsistencies in the future, and also maintain clarity in using Git)
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "weijinglin (via GitHub)" <gi...@apache.org>.
weijinglin closed pull request #192: feat(llm):improve some RAG function UT(tests)
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


Re: [PR] feat(llm):improve some RAG function UT(tests) [incubator-hugegraph-ai]

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #192:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/192#discussion_r1981156314


##########
hugegraph-llm/run_tests.py:
##########
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3

Review Comment:
   Also we should enable the test in the related CI file:  (So it could run automatically)
   like add a `.github/workflows/graph_rag.yml` ?
   
   could refer: https://github.com/apache/incubator-hugegraph-ai/blob/ca28faf29b1d3499467cc8b366b4462b829182e5/.github/workflows/hugegraph-python-client.yml#L66



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org