Skip to content

refactor(api): tighten types in core/rag batch 1#34702

Open
tmimmanuel wants to merge 8 commits intolanggenius:mainfrom
tmimmanuel:refactor/pyright-core-rag-pr1
Open

refactor(api): tighten types in core/rag batch 1#34702
tmimmanuel wants to merge 8 commits intolanggenius:mainfrom
tmimmanuel:refactor/pyright-core-rag-pr1

Conversation

@tmimmanuel
Copy link
Copy Markdown
Contributor

Summary

Refactor tracked in #26412: improve static typing for api/core/rag by resolving Pyright/Basedpyright findings in the first batch, without changing intended runtime behavior.

What changed

  • Retrieval: address an unused binding flagged by the type checker.
  • Vector DB adapters (Huawei / Matrixone / Upstash): align annotations and method contracts with BaseVector (structured params typing, avoid private-member access from decorators via a public accessor, ensure add_texts matches the abstract return type).
  • Text splitters: clarify tokenizer option types and remove dead code from an unused alternate encoding path while keeping the public API stable.
  • IRIS: allow the optional iris dependency in Pyright config (allowedUntypedLibraries) where stubs are not available.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 01:25:50.817740184 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 01:25:42.304722147 +0000
@@ -128,8 +128,6 @@
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
 ERROR Unpacked keyword argument `bool | Unknown | None` is not assignable to parameter `max_retries` with type `Decimal | bool | bytes | float | int | str` in function `ElasticSearchConfig.__init__` [bad-argument-type]
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
-ERROR `tuple[str, str]` is not assignable to TypedDict key `basic_auth` with type `bool | int | list[str]` [bad-typed-dict-key]
-  --> core/rag/datasource/vdb/huawei/huawei_cloud_vector.py:51:36
 ERROR Class member `LindormVectorStore.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
   --> core/rag/datasource/vdb/lindorm/lindorm_vector.py:84:9
 ERROR `str | None` is not assignable to TypedDict key `routing` with type `str` [bad-typed-dict-key]
@@ -235,8 +233,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]
@@ -289,6 +285,8 @@
    --> core/rag/index_processor/processor/qa_index_processor.py:205:16
 ERROR No matching overload found for function `core.model_manager.ModelInstance.invoke_llm` called with arguments: (prompt_messages=list[SystemPromptMessage | UserPromptMessage], tools=list[PromptMessageTool], stream=Literal[False], model_parameters=dict[str, float | int]) [no-matching-overload]
   --> core/rag/retrieval/router/multi_dataset_function_call_router.py:32:58
+ERROR Could not import `AbstractSet` from `collections.abc` [missing-module-attribute]
+ --> core/rag/splitter/text_splitter.py:7:29
 ERROR Class member `MCPToolProviderController.entity` overrides parent class `ToolProviderController` in an inconsistent manner [bad-override]
   --> core/tools/mcp_tool/provider.py:33:14
 ERROR Class member `PluginToolProviderController.entity` overrides parent class `BuiltinToolProviderController` in an inconsistent manner [bad-override]

auto-merge was automatically disabled April 8, 2026 14:03

Head branch was pushed to by a user without write access

@tmimmanuel tmimmanuel force-pushed the refactor/pyright-core-rag-pr1 branch from b2fe82c to a03b2e4 Compare April 8, 2026 14:03
@tmimmanuel tmimmanuel requested a review from laipz8200 as a code owner April 8, 2026 14:03
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 14:04:38.831329157 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 14:04:29.191101261 +0000
@@ -128,8 +128,6 @@
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
 ERROR Unpacked keyword argument `bool | Unknown | None` is not assignable to parameter `max_retries` with type `Decimal | bool | bytes | float | int | str` in function `ElasticSearchConfig.__init__` [bad-argument-type]
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
-ERROR `tuple[str, str]` is not assignable to TypedDict key `basic_auth` with type `bool | int | list[str]` [bad-typed-dict-key]
-  --> core/rag/datasource/vdb/huawei/huawei_cloud_vector.py:51:36
 ERROR Class member `LindormVectorStore.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
   --> core/rag/datasource/vdb/lindorm/lindorm_vector.py:84:9
 ERROR `str | None` is not assignable to TypedDict key `routing` with type `str` [bad-typed-dict-key]
@@ -235,8 +233,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]
@@ -4989,7 +4985,7 @@
 ERROR Argument `Iterator[Any | Unknown] | Iterator[Any]` is not assignable to parameter `invoke_result` with type `Generator[Unknown]` in function `core.rag.retrieval.router.multi_dataset_react_route.ReactMultiDatasetRouter._handle_invoke_result` [bad-argument-type]
    --> tests/unit_tests/core/rag/retrieval/test_multi_dataset_react_route.py:199:52
 ERROR Argument `None` is not assignable to parameter `text` with type `str` in function `core.rag.splitter.text_splitter.RecursiveCharacterTextSplitter.split_text` [bad-argument-type]
-    --> tests/unit_tests/core/rag/splitter/test_text_splitter.py:1877:42
+    --> tests/unit_tests/core/rag/splitter/test_text_splitter.py:1854:42
 ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:80:53
 ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 14:06:37.891665830 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 14:06:27.855617238 +0000
@@ -128,8 +128,6 @@
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
 ERROR Unpacked keyword argument `bool | Unknown | None` is not assignable to parameter `max_retries` with type `Decimal | bool | bytes | float | int | str` in function `ElasticSearchConfig.__init__` [bad-argument-type]
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
-ERROR `tuple[str, str]` is not assignable to TypedDict key `basic_auth` with type `bool | int | list[str]` [bad-typed-dict-key]
-  --> core/rag/datasource/vdb/huawei/huawei_cloud_vector.py:51:36
 ERROR Class member `LindormVectorStore.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
   --> core/rag/datasource/vdb/lindorm/lindorm_vector.py:84:9
 ERROR `str | None` is not assignable to TypedDict key `routing` with type `str` [bad-typed-dict-key]
@@ -235,8 +233,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]
@@ -4989,7 +4985,7 @@
 ERROR Argument `Iterator[Any | Unknown] | Iterator[Any]` is not assignable to parameter `invoke_result` with type `Generator[Unknown]` in function `core.rag.retrieval.router.multi_dataset_react_route.ReactMultiDatasetRouter._handle_invoke_result` [bad-argument-type]
    --> tests/unit_tests/core/rag/retrieval/test_multi_dataset_react_route.py:199:52
 ERROR Argument `None` is not assignable to parameter `text` with type `str` in function `core.rag.splitter.text_splitter.RecursiveCharacterTextSplitter.split_text` [bad-argument-type]
-    --> tests/unit_tests/core/rag/splitter/test_text_splitter.py:1877:42
+    --> tests/unit_tests/core/rag/splitter/test_text_splitter.py:1854:42
 ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:80:53
 ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]

@tmimmanuel
Copy link
Copy Markdown
Contributor Author

@asukaminato0721 Please review this PR.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors api/core/rag to reduce Pyright/Basedpyright findings by tightening type annotations and aligning some adapter/test code with updated contracts.

Changes:

  • Adjust vector DB adapters/tests (Matrixone / Upstash / Huawei) to better match BaseVector contracts and public APIs.
  • Simplify text splitter/tokenizer typing and remove unused/dead logic paths, with corresponding unit test updates.
  • Update Pyright configuration to allow an untyped optional dependency (iris).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
api/tests/unit_tests/core/rag/splitter/test_text_splitter.py Updates splitter tests to match the new from_encoder behavior and removes frame-introspection.
api/tests/unit_tests/core/rag/datasource/vdb/matrixone/test_matrixone_vector.py Updates tests to use the new public get_client accessor.
api/pyrightconfig.json Adds iris to allowedUntypedLibraries.
api/core/rag/splitter/text_splitter.py Tightens tokenizer option types (allowed_special / disallowed_special) and avoids mutable defaults.
api/core/rag/splitter/fixed_text_splitter.py Removes token-counting encoder logic and keeps a character-length encoder.
api/core/rag/datasource/vdb/upstash/upstash_vector.py Makes add_texts return ids and reworks vector id assignment.
api/core/rag/datasource/vdb/matrixone/matrixone_vector.py Renames _get_client to get_client and updates the decorator/call sites accordingly.
api/core/rag/datasource/vdb/huawei/huawei_cloud_vector.py Adds explicit type annotation for Elasticsearch params dict.
api/core/rag/datasource/retrieval_service.py Removes an unused loop binding in as_completed iteration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/core/rag/splitter/fixed_text_splitter.py
@tmimmanuel tmimmanuel force-pushed the refactor/pyright-core-rag-pr1 branch from 20d8fc3 to d600001 Compare April 9, 2026 03:11
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-09 03:13:12.944924875 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-09 03:13:03.879957468 +0000
@@ -126,8 +126,6 @@
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
 ERROR Unpacked keyword argument `bool | Unknown | None` is not assignable to parameter `max_retries` with type `Decimal | bool | bytes | float | int | str` in function `ElasticSearchConfig.__init__` [bad-argument-type]
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
-ERROR `tuple[str, str]` is not assignable to TypedDict key `basic_auth` with type `bool | int | list[str]` [bad-typed-dict-key]
-  --> core/rag/datasource/vdb/huawei/huawei_cloud_vector.py:51:36
 ERROR Class member `LindormVectorStore.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
   --> core/rag/datasource/vdb/lindorm/lindorm_vector.py:84:9
 ERROR `str | None` is not assignable to TypedDict key `routing` with type `str` [bad-typed-dict-key]
@@ -233,8 +231,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-09 03:15:26.627817722 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-09 03:15:17.336824107 +0000
@@ -126,8 +126,6 @@
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
 ERROR Unpacked keyword argument `bool | Unknown | None` is not assignable to parameter `max_retries` with type `Decimal | bool | bytes | float | int | str` in function `ElasticSearchConfig.__init__` [bad-argument-type]
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
-ERROR `tuple[str, str]` is not assignable to TypedDict key `basic_auth` with type `bool | int | list[str]` [bad-typed-dict-key]
-  --> core/rag/datasource/vdb/huawei/huawei_cloud_vector.py:51:36
 ERROR Class member `LindormVectorStore.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
   --> core/rag/datasource/vdb/lindorm/lindorm_vector.py:84:9
 ERROR `str | None` is not assignable to TypedDict key `routing` with type `str` [bad-typed-dict-key]
@@ -233,8 +231,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]

@tmimmanuel tmimmanuel closed this Apr 9, 2026
@tmimmanuel tmimmanuel reopened this Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-09 03:54:18.915600965 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-09 03:54:09.474609842 +0000
@@ -126,8 +126,6 @@
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
 ERROR Unpacked keyword argument `bool | Unknown | None` is not assignable to parameter `max_retries` with type `Decimal | bool | bytes | float | int | str` in function `ElasticSearchConfig.__init__` [bad-argument-type]
    --> core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py:355:40
-ERROR `tuple[str, str]` is not assignable to TypedDict key `basic_auth` with type `bool | int | list[str]` [bad-typed-dict-key]
-  --> core/rag/datasource/vdb/huawei/huawei_cloud_vector.py:51:36
 ERROR Class member `LindormVectorStore.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
   --> core/rag/datasource/vdb/lindorm/lindorm_vector.py:84:9
 ERROR `str | None` is not assignable to TypedDict key `routing` with type `str` [bad-typed-dict-key]
@@ -233,8 +231,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]

@tmimmanuel
Copy link
Copy Markdown
Contributor Author

@asukaminato0721 Can you review again please?

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-10 17:46:16.582436777 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-10 17:46:07.598398443 +0000
@@ -245,8 +245,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]

@tmimmanuel
Copy link
Copy Markdown
Contributor Author

@asukaminato0721
I updated code. Please review my code again. Thanks.

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-13 03:07:05.403262669 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-13 03:06:56.443120694 +0000
@@ -245,8 +245,6 @@
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:71:20
 ERROR `None` is not subscriptable [unsupported-operation]
   --> core/rag/datasource/vdb/tidb_on_qdrant/tidb_service.py:72:35
-ERROR Class member `UpstashVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
-  --> core/rag/datasource/vdb/upstash/upstash_vector.py:47:9
 ERROR Class member `VikingDBVector.add_texts` overrides parent class `BaseVector` in an inconsistent manner [bad-override]
    --> core/rag/datasource/vdb/vikingdb/vikingdb_vector.py:117:9
 ERROR Object of class `list` has no attribute `fields` [missing-attribute]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@tmimmanuel
Copy link
Copy Markdown
Contributor Author

Hi, @asukaminato0721 Sorry for interrupting you.
I fixed conflict problems. Please review my PR if you have time. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants