Skip to content

refactor: refactor test local inference#952

Merged
joein merged 1 commit into
devfrom
refactor-tests-local-inference
Apr 17, 2025
Merged

refactor: refactor test local inference#952
joein merged 1 commit into
devfrom
refactor-tests-local-inference

Conversation

@joein

@joein joein commented Apr 15, 2025

Copy link
Copy Markdown
Member

this refactoring reduces the time required to run these tests on local machine from 3.5 minutes to ~40 seconds

After reviewing the tests, I figured out, that congruence tests are not required here, cuz here we're testing the code which is the same for both local and remote modes, also it does not make sense running it with both http and grpc for the same reason.

Also @hh-space-invader tried caching embedding generation itself, however, after a couple of benchmarks, I've got the results which show that caching embedding generation won't bring as much benefits

@joein joein requested a review from hh-space-invader April 15, 2025 17:35
@netlify

netlify Bot commented Apr 15, 2025

Copy link
Copy Markdown

Deploy Preview for poetic-froyo-8baba7 ready!

Name Link
🔨 Latest commit eaae4e9
🔍 Latest deploy log https://app.netlify.com/sites/poetic-froyo-8baba7/deploys/67fe98c3f9a9cb00083e939a
😎 Deploy Preview https://deploy-preview-952--poetic-froyo-8baba7.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@coderabbitai

coderabbitai Bot commented Apr 15, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The test suite in tests/embed_tests/test_local_inference.py was refactored to eliminate all references to a secondary remote_client and any logic related to comparing results between local_client and remote_client. All test functions now exclusively use a single local_client instance configured with an in-memory Qdrant database. The prefer_grpc parameter and its related test parameterization were removed from the test cases.

A new pytest fixture named cached_embeddings was introduced. This fixture uses unittest.mock.patch and functools.lru_cache to cache and mock the instantiation of embedding models (TextEmbedding, SparseTextEmbedding, LateInteractionTextEmbedding, ImageEmbedding) for the duration of the test session. The fixture is applied to all test functions to ensure consistent and efficient use of embedding model instances.

Constants COLBERT_MODEL_NAME and COLBERT_DIM were updated, and the compare_collections utility, along with its related import and usage, was removed. The arg_interceptor helper remains unchanged. All test logic now centers on single-client operations, with cross-client assertions and operations omitted.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
tests/embed_tests/test_local_inference.py (5)

33-37: Consider refactoring star-arg usage after a named argument.

Static analysis flags the pattern TextEmbedding(model_name=model_name, *args, **kwargs) as B026. While it works, some style guides discourage mixing named arguments and star-args in this manner.

🧰 Tools
🪛 Ruff (0.8.2)

36-36: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


39-42: Consider refactoring star-arg usage after a named argument.

Identical reasoning as above for _cached_sparse_text_embedding.

🧰 Tools
🪛 Ruff (0.8.2)

41-41: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


44-47: Consider refactoring star-arg usage after a named argument.

Identical reasoning as above for _cached_late_interaction_text_embedding.

🧰 Tools
🪛 Ruff (0.8.2)

46-46: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


49-52: Consider refactoring star-arg usage after a named argument.

Identical reasoning as above for _cached_image_embedding.

🧰 Tools
🪛 Ruff (0.8.2)

51-51: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


379-379: Remove unused variable.

retrieved_point_id_0 is set but never referenced, triggering a static analysis warning. Consider removing it:

- retrieved_point_id_0 = local_client.retrieve(COLLECTION_NAME, ids=[0], with_vectors=True)[0]
+ local_client.retrieve(COLLECTION_NAME, ids=[0], with_vectors=True)
🧰 Tools
🪛 Ruff (0.8.2)

379-379: Local variable retrieved_point_id_0 is assigned to but never used

Remove assignment to unused variable retrieved_point_id_0

(F841)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0bbada and eaae4e9.

📒 Files selected for processing (1)
  • tests/embed_tests/test_local_inference.py (27 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
tests/embed_tests/test_local_inference.py

36-36: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


41-41: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


46-46: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


51-51: Star-arg unpacking after a keyword argument is strongly discouraged

(B026)


379-379: Local variable retrieved_point_id_0 is assigned to but never used

Remove assignment to unused variable retrieved_point_id_0

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Redirect rules - poetic-froyo-8baba7
  • GitHub Check: Header rules - poetic-froyo-8baba7
  • GitHub Check: Pages changed - poetic-froyo-8baba7
  • GitHub Check: Python 3.13.x on ubuntu-latest test
  • GitHub Check: Python 3.12.x on ubuntu-latest test
  • GitHub Check: Python 3.11.x on ubuntu-latest test
  • GitHub Check: Python 3.10.x on ubuntu-latest test
  • GitHub Check: Python 3.9.x on ubuntu-latest test
🔇 Additional comments (34)
tests/embed_tests/test_local_inference.py (34)

3-5: No concerns.

These import statements appear valid and straightforward.


10-10: No issues found.

Importing the embedder is necessary for the mock patches and embedding logic.


14-19: No issues found.

These imports from fastembed_common appear correct and in line with test objectives.


54-82: Fixture implementation looks good.

Leveraging lru_cache for embedding objects and patching them in a fixture is a neat way to speed up tests and reduce repetitive object creation.


133-133: No issues found.

The definition of test_upsert(cached_embeddings) appears valid and aligned with the test flow.


240-259: Confirm necessity of remote_client usage.

According to the PR objectives, redundant references to remote vs local may be unnecessary. Please verify if these lines and assertions truly need remote_client, or if everything can be tested locally.


288-293: No issues found.


303-303: No issues found.


305-307: No issues found.


311-315: No issues found.


322-326: No issues found.


333-337: No issues found.


380-380: No issues found.


412-412: No issues found.


495-507: No issues found.


517-518: No issues found.


584-588: No issues found.


607-611: No issues found.


639-644: No issues found.


646-650: No issues found.


662-663: No issues found.


669-669: No issues found.


684-688: No issues found.


759-759: No issues found.


767-767: No issues found.


771-782: No issues found.


783-784: No issues found.


826-827: No issues found.


1000-1003: No issues found.


1095-1100: No issues found.


1118-1122: Confirm necessity of remote_client.

This test still relies on remote_client. Please confirm whether remote inference is intentionally preserved or could be simplified.


1140-1140: No issues found.


1337-1340: No issues found.


1437-1439: No issues found.

@joein joein merged commit 6544484 into dev Apr 17, 2025
joein added a commit that referenced this pull request Apr 22, 2025
This was referenced Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants