Skip to content

Commit fa896c8

Browse files
committed
🚧 added hash the examples dictionary and include in cache key
1 parent b40ecfb commit fa896c8

File tree

1 file changed

+6
-1
lines changed
  • nemoguardrails/library/embedding_topic_detector

1 file changed

+6
-1
lines changed

nemoguardrails/library/embedding_topic_detector/actions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
import hashlib
17+
import json
1618
import logging
1719
from typing import Dict, List, Optional
1820

@@ -77,7 +79,10 @@ async def detect(self, query: str) -> Dict:
7779

7880
async def _check(context: Optional[dict], llm_task_manager, message_key: str) -> dict:
7981
config = llm_task_manager.config.rails.config.embedding_topic_detector
80-
cache_key = f"{config['embedding_model']}_{config['embedding_engine']}_{config.get('threshold', 0.75)}_{config.get('top_k', 3)}"
82+
examples_hash = hashlib.sha256(
83+
json.dumps(config["examples"], sort_keys=True).encode("utf-8")
84+
).hexdigest()
85+
cache_key = f"{config['embedding_model']}_{config['embedding_engine']}_{config.get('threshold', 0.75)}_{config.get('top_k', 3)}_{examples_hash}"
8186

8287
if cache_key not in _detector_cache:
8388
_detector_cache[cache_key] = EmbeddingTopicDetector(

0 commit comments

Comments
 (0)