|
|
1 год назад | |
|---|---|---|
| .. | ||
| README.md | 1 год назад | |
| __init__.py | 1 год назад | |
| clickzetta_vector.py | 1 год назад | |
This module provides integration with Clickzetta Lakehouse as a vector database for Dify.
All seven configuration parameters are required:
# Authentication
CLICKZETTA_USERNAME=your_username
CLICKZETTA_PASSWORD=your_password
# Instance configuration
CLICKZETTA_INSTANCE=your_instance_id
CLICKZETTA_SERVICE=api.clickzetta.com
CLICKZETTA_WORKSPACE=your_workspace
CLICKZETTA_VCLUSTER=your_vcluster
CLICKZETTA_SCHEMA=your_schema
# Batch processing
CLICKZETTA_BATCH_SIZE=100
# Full-text search configuration
CLICKZETTA_ENABLE_INVERTED_INDEX=true
CLICKZETTA_ANALYZER_TYPE=chinese # Options: keyword, english, chinese, unicode
CLICKZETTA_ANALYZER_MODE=smart # Options: max_word, smart
# Vector search configuration
CLICKZETTA_VECTOR_DISTANCE_FUNCTION=cosine_distance # Options: l2_distance, cosine_distance
In your Dify configuration, set:
VECTOR_STORE=clickzetta
Clickzetta will automatically create tables with the following structure:
CREATE TABLE <collection_name> (
id STRING NOT NULL,
content STRING NOT NULL,
metadata JSON,
vector VECTOR(FLOAT, <dimension>) NOT NULL,
PRIMARY KEY (id)
);
-- Vector index for similarity search
CREATE VECTOR INDEX idx_<collection_name>_vec
ON TABLE <schema>.<collection_name>(vector)
PROPERTIES (
"distance.function" = "cosine_distance",
"scalar.type" = "f32"
);
-- Inverted index for full-text search (if enabled)
CREATE INVERTED INDEX idx_<collection_name>_text
ON <schema>.<collection_name>(content)
PROPERTIES (
"analyzer" = "chinese",
"mode" = "smart"
);
Clickzetta supports advanced full-text search with multiple analyzers:
keyword: No tokenization, treats the entire string as a single token
english: Designed for English text
chinese: Chinese text tokenizer
unicode: Multi-language tokenizer based on Unicode
MATCH_ALL(column, query): All terms must be presentMATCH_ANY(column, query): At least one term must be presentMATCH_PHRASE(column, query): Exact phrase matchingMATCH_PHRASE_PREFIX(column, query): Phrase prefix matchingMATCH_REGEXP(column, pattern): Regular expression matching SET cz.vector.index.search.ef=64;
Use appropriate distance functions:
cosine_distance: Best for normalized embeddings (e.g., from language models)l2_distance: Best for raw feature vectorsChoose the right analyzer:
keyword for exact matchingCombine with vector search:
SHOW INDEX FROM <schema>.<table_name>;
EXPLAIN SELECT ... WHERE l2_distance(...) < threshold;
Look for vector_index_search_type in the execution plan.
TOKENIZE() function to test tokenization:
sql
SELECT TOKENIZE('your text', map('analyzer', 'chinese', 'mode', 'smart'));
## Limitations
1. Vector operations don't support ORDER BY or GROUP BY directly on vector columns
1. Full-text search relevance scores are not provided by Clickzetta
1. Inverted index creation may fail for very large existing tables (continue without error)
1. Index naming constraints:
- Index names must be unique within a schema
- Only one vector index can be created per column
- The implementation uses timestamps to ensure unique index names
1. A column can only have one vector index at a time
## References
- Clickzetta Vector Search Documentation
- Clickzetta Inverted Index Documentation
- Clickzetta SQL Functions