ExLLM.Testing.TestCacheMatcher (ex_llm v0.8.1)

View Source

Intelligent matching of requests to cached responses.

This module provides sophisticated request-to-cache matching strategies including exact matching, fuzzy matching, content-based matching, and test context-aware matching for the automatic test response caching system.

Summary

Functions

Calculate similarity score between two requests.

Find context-aware match considering test module and tags.

Find exact match for a request in cached responses.

Extract message content from request for semantic matching.

Find best match using comprehensive strategy.

Find fuzzy match for a request with configurable tolerance.

Normalize request for comparison.

Find semantic match based on request content similarity.

Types

cached_request()

@type cached_request() :: map()

match_result()

@type match_result() :: {:ok, map()} | :miss

Functions

calculate_similarity(request1, request2)

@spec calculate_similarity(map(), map()) :: float()

Calculate similarity score between two requests.

context_match(request, cached_requests, test_context)

@spec context_match(map(), [cached_request()], map()) :: match_result()

Find context-aware match considering test module and tags.

exact_match(request, cached_requests)

@spec exact_match(map(), [cached_request()]) :: match_result()

Find exact match for a request in cached responses.

extract_message_content(request)

@spec extract_message_content(map()) :: String.t()

Extract message content from request for semantic matching.

find_best_match(request, cached_requests, strategy \\ :comprehensive)

@spec find_best_match(map(), [cached_request()], atom()) :: match_result()

Find best match using comprehensive strategy.

fuzzy_match(request, cached_requests, tolerance \\ 0.9)

@spec fuzzy_match(map(), [cached_request()], float()) :: match_result()

Find fuzzy match for a request with configurable tolerance.

generate_request_signature(request)

normalize_request(request)

@spec normalize_request(map()) :: map()

Normalize request for comparison.

semantic_match(request, cached_requests)

@spec semantic_match(map(), [cached_request()]) :: match_result()

Find semantic match based on request content similarity.