Skip to content

Add Apache Doris vector store support - #4

Closed
jaffrey-deepsource wants to merge 3 commits into
mainfrom
doris_vector
Closed

Add Apache Doris vector store support #4
jaffrey-deepsource wants to merge 3 commits into
mainfrom
doris_vector

Conversation

@jaffrey-deepsource

Copy link
Copy Markdown

No description provided.

dataroaring and others added 3 commits January 13, 2026 08:41
This commit adds Apache Doris as a new vector database option for Dify's RAG system.

Features:
- Vector similarity search using cosine distance
- Full-text search with BM25 scoring and inverted indexes
- Hybrid search combining vector and text search
- High-performance bulk data loading via StreamLoad
- Connection pooling for efficient resource management
- Support for multi-tenant isolation

Components added:
- DorisVector: Main vector database implementation with cleaned code
- DorisConfig: Configuration model with validation
- DorisConnectionPool: Thread-safe connection management
- DorisVectorFactory: Factory for creating Doris instances
- DORIS_SETUP.md: Complete setup guide in English
- Add type annotations to fix mypy errors (pool config dict, params lists)
- Add USE database statement in _get_cursor to ensure database context
- Add _wait_for_table_normal_state method to wait for schema changes
  before creating text index (fixes index creation race condition)
- Extend Redis lock timeout to accommodate schema change waiting
- Update unit tests to account for new USE database statement
@deepsource-development

deepsource-development Bot commented Feb 12, 2026

Copy link
Copy Markdown

DeepSource Code Review

DeepSource reviewed changes in the commit range b76c8fa..413534b on this pull request. Below is the summary for the review, and you can see the individual issues we found as review comments.

For detailed review results, please see the PR on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. Please see the DeepSource dashboard for this PR to view those issues.

PR Report Card

Security × 2 issues Overall PR Quality   

Focus Area: Reliability

Guidance
Address 10 critical 'Unexpected any' type issues across various files to improve type safety.

Grade capped at D due to multiple critical issues
Reliability × 3631 issues
Complexity × 216 issues
Hygiene × 748 issues

Code Review Summary

Analyzer Status Summary Details
JavaScript 4590 new issues detected. Review ↗
Python 8 new issues detected. 1 existing issue fixed. Review ↗
Secrets No new issues detected. Review ↗
How are these analyzer statuses calculated?

Administrators can configure which issue categories are reported and cause analysis to be marked as failed when detected. This helps prevent bad and insecure code from being introduced in the codebase. If you're an administrator, you can modify this in the repository's settings.


💡 If you're a repository administrator, you can configure the quality gates from the settings.

# Table name format: embedding_ + collection_name
# collection_name already includes Vector_index_ prefix and _Node suffix from Dataset.gen_collection_name_by_id
self.table_name = f"embedding_{collection_name}"
self.index_hash = hashlib.md5(self.table_name.encode()).hexdigest()[:8]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

`hashlib.md5` enables collision attacks


The code uses hashlib.md5 to compute a hash of self.table_name, which is cryptographically broken and susceptible to collision attacks. Attackers could generate different inputs that produce the same hash, undermining trust or causing security breaches.

Replace hashlib.md5 with stronger algorithms such as hashlib.sha256 or hashlib.sha512 to ensure cryptographic security and avoid collisions.

with self._get_cursor() as cur:
try:
placeholders = ",".join(["%s"] * len(ids))
cur.execute(f"DELETE FROM `{self.table_name}` WHERE id IN ({placeholders})", ids)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

String-based SQL query construction enables injection attacks


Constructing the SQL DELETE query with f-string interpolation using self.table_name and the placeholders string directly inserts data into the SQL command, exposing the code to SQL injection attacks. An attacker can manipulate self.table_name or ids to execute arbitrary SQL, potentially deleting or corrupting database data.

Use parameterized queries and avoid interpolating untrusted variables directly in SQL command strings. Validate or whitelist self.table_name and pass ids as query parameters to the database adapter to ensure safe escaping and prevent injection.

assert config.text_search_analyzer == "chinese"
assert config.streamload_port == 8030

def test_invalid_analyzer_raises_error(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instance method without `self` wastes memory and CPU


The method test_invalid_analyzer_raises_error is defined with self as parameter but never uses it, resulting in creation of bound methods for class instances and increased memory and CPU consumption. This overhead persists for every instance where the method is accessed.
Decorate the method with @staticmethod to indicate it does not depend on instance state. This avoids creation of bound methods and reduces memory and computation overhead.

mock_pool = MagicMock()
mock_pool_class.return_value = mock_pool

pool = DorisConnectionPool(self.config)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Assigned variable `pool` is never used


The variable pool holds a DorisConnectionPool object but is never used after its assignment, which wastes memory and may confuse maintainers about its purpose.

Remove the assignment or rename the variable to _ or _unused to indicate intentional non-use, cleaning up the code and improving readability.

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.

3 participants