Spaces:
Runtime error
Runtime error
feat: implement hybrid similarity ranking and search engine modules to improve project retrieval accuracy
Browse files- Data/database/__pycache__/sql_connector.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/config.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/context_builder.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/idea_generator.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/prompt_builder.cpython-313.pyc +0 -0
- src/recommendation_engine/__pycache__/validator.cpython-313.pyc +0 -0
- src/recommendation_engine/chatbot_engine.py +2 -3
- src/similarity_model/__pycache__/__init__.cpython-313.pyc +0 -0
- src/similarity_model/__pycache__/embedding_engine.cpython-313.pyc +0 -0
- src/similarity_model/__pycache__/feature_similarity.cpython-313.pyc +0 -0
- src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc +0 -0
- src/similarity_model/__pycache__/semantic_search.cpython-313.pyc +0 -0
- src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc +0 -0
- src/similarity_model/hybrid_ranker.py +16 -22
- src/similarity_model/similarity_engine.py +0 -1
Data/database/__pycache__/sql_connector.cpython-313.pyc
CHANGED
|
Binary files a/Data/database/__pycache__/sql_connector.cpython-313.pyc and b/Data/database/__pycache__/sql_connector.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc and b/src/recommendation_engine/__pycache__/chatbot_engine.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/config.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/config.cpython-313.pyc and b/src/recommendation_engine/__pycache__/config.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/context_builder.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/context_builder.cpython-313.pyc and b/src/recommendation_engine/__pycache__/context_builder.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/idea_generator.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/idea_generator.cpython-313.pyc and b/src/recommendation_engine/__pycache__/idea_generator.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/prompt_builder.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/prompt_builder.cpython-313.pyc and b/src/recommendation_engine/__pycache__/prompt_builder.cpython-313.pyc differ
|
|
|
src/recommendation_engine/__pycache__/validator.cpython-313.pyc
CHANGED
|
Binary files a/src/recommendation_engine/__pycache__/validator.cpython-313.pyc and b/src/recommendation_engine/__pycache__/validator.cpython-313.pyc differ
|
|
|
src/recommendation_engine/chatbot_engine.py
CHANGED
|
@@ -1014,9 +1014,8 @@ def chatbot(user_id: str, user_input: str):
|
|
| 1014 |
|
| 1015 |
if text.startswith(pattern + " "):
|
| 1016 |
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
)[1].strip()
|
| 1020 |
|
| 1021 |
if (
|
| 1022 |
extracted_title
|
|
|
|
| 1014 |
|
| 1015 |
if text.startswith(pattern + " "):
|
| 1016 |
|
| 1017 |
+
pattern_idx = user_input.lower().find(pattern)
|
| 1018 |
+
extracted_title = user_input[pattern_idx + len(pattern):].strip() if pattern_idx != -1 else ""
|
|
|
|
| 1019 |
|
| 1020 |
if (
|
| 1021 |
extracted_title
|
src/similarity_model/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/__init__.cpython-313.pyc and b/src/similarity_model/__pycache__/__init__.cpython-313.pyc differ
|
|
|
src/similarity_model/__pycache__/embedding_engine.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/embedding_engine.cpython-313.pyc and b/src/similarity_model/__pycache__/embedding_engine.cpython-313.pyc differ
|
|
|
src/similarity_model/__pycache__/feature_similarity.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/feature_similarity.cpython-313.pyc and b/src/similarity_model/__pycache__/feature_similarity.cpython-313.pyc differ
|
|
|
src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc and b/src/similarity_model/__pycache__/hybrid_ranker.cpython-313.pyc differ
|
|
|
src/similarity_model/__pycache__/semantic_search.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/semantic_search.cpython-313.pyc and b/src/similarity_model/__pycache__/semantic_search.cpython-313.pyc differ
|
|
|
src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc
CHANGED
|
Binary files a/src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc and b/src/similarity_model/__pycache__/similarity_engine.cpython-313.pyc differ
|
|
|
src/similarity_model/hybrid_ranker.py
CHANGED
|
@@ -67,15 +67,11 @@ def compute_hybrid_score(
|
|
| 67 |
|
| 68 |
shared_count = feature_count - unique_query_count
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
if shared_count >= 6 and unique_query_count <= 1:
|
| 74 |
return 0.95
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
if coverage >= 0.90 and feature_score >= 0.65:
|
| 80 |
return round(
|
| 81 |
clamp(
|
|
@@ -86,15 +82,7 @@ def compute_hybrid_score(
|
|
| 86 |
4
|
| 87 |
)
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
if feature_score == 0 or coverage == 0:
|
| 93 |
-
return round(clamp(0.85 * semantic_score), 4)
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
semantic_w, feature_w, coverage_w = get_dynamic_weights(
|
| 99 |
feature_count, coverage
|
| 100 |
)
|
|
@@ -105,11 +93,10 @@ def compute_hybrid_score(
|
|
| 105 |
coverage_w * coverage
|
| 106 |
)
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
if feature_score < 0.40:
|
| 113 |
penalty = 0.50 + (feature_score / 0.40) * 0.50
|
| 114 |
score *= penalty
|
| 115 |
|
|
@@ -121,13 +108,20 @@ def compute_originality(
|
|
| 121 |
total_query_features: int
|
| 122 |
) -> float:
|
| 123 |
"""
|
| 124 |
-
Originality Score (0-100)
|
| 125 |
-
|
|
|
|
|
|
|
| 126 |
"""
|
| 127 |
hybrid_score = clamp(hybrid_score)
|
| 128 |
|
| 129 |
originality = 100.0 * (1.0 - hybrid_score)
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
return round(max(0.0, min(100.0, originality)), 2)
|
| 132 |
|
| 133 |
def compute_confidence(
|
|
|
|
| 67 |
|
| 68 |
shared_count = feature_count - unique_query_count
|
| 69 |
|
| 70 |
+
# Hard duplicate: most features shared, almost nothing unique
|
|
|
|
|
|
|
| 71 |
if shared_count >= 6 and unique_query_count <= 1:
|
| 72 |
return 0.95
|
| 73 |
|
| 74 |
+
# Near-total feature coverage with high similarity
|
|
|
|
|
|
|
| 75 |
if coverage >= 0.90 and feature_score >= 0.65:
|
| 76 |
return round(
|
| 77 |
clamp(
|
|
|
|
| 82 |
4
|
| 83 |
)
|
| 84 |
|
| 85 |
+
# Get adaptive weights regardless of feature availability
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
semantic_w, feature_w, coverage_w = get_dynamic_weights(
|
| 87 |
feature_count, coverage
|
| 88 |
)
|
|
|
|
| 93 |
coverage_w * coverage
|
| 94 |
)
|
| 95 |
|
| 96 |
+
# Only penalise low feature score when features actually exist to compare.
|
| 97 |
+
# Skipping this when feature_score==0 prevents an unfair 50% penalty
|
| 98 |
+
# on DB projects that have no stored features.
|
| 99 |
+
if feature_score > 0 and feature_score < 0.40:
|
|
|
|
| 100 |
penalty = 0.50 + (feature_score / 0.40) * 0.50
|
| 101 |
score *= penalty
|
| 102 |
|
|
|
|
| 108 |
total_query_features: int
|
| 109 |
) -> float:
|
| 110 |
"""
|
| 111 |
+
Originality Score (0-100).
|
| 112 |
+
Base score is (1 - hybrid_score) * 100.
|
| 113 |
+
Bonus of up to +10 points when the query has many features
|
| 114 |
+
that are unique vs the candidate (genuine differentiation signal).
|
| 115 |
"""
|
| 116 |
hybrid_score = clamp(hybrid_score)
|
| 117 |
|
| 118 |
originality = 100.0 * (1.0 - hybrid_score)
|
| 119 |
|
| 120 |
+
# Uniqueness bonus: reward projects whose features don't overlap
|
| 121 |
+
if total_query_features > 0:
|
| 122 |
+
uniqueness_ratio = unique_query_features / total_query_features
|
| 123 |
+
originality = min(100.0, originality + (uniqueness_ratio * 10.0))
|
| 124 |
+
|
| 125 |
return round(max(0.0, min(100.0, originality)), 2)
|
| 126 |
|
| 127 |
def compute_confidence(
|
src/similarity_model/similarity_engine.py
CHANGED
|
@@ -43,7 +43,6 @@ def build_raw_text(
|
|
| 43 |
"""
|
| 44 |
parts = [
|
| 45 |
str(title).strip(),
|
| 46 |
-
str(title).strip(),
|
| 47 |
str(abstract).strip(),
|
| 48 |
str(description).strip()
|
| 49 |
]
|
|
|
|
| 43 |
"""
|
| 44 |
parts = [
|
| 45 |
str(title).strip(),
|
|
|
|
| 46 |
str(abstract).strip(),
|
| 47 |
str(description).strip()
|
| 48 |
]
|