Search documentation of Ragex

# Ragex.Retrieval.QueryExpansion (Ragex v0.4.0)

View Source

Query expansion using MetaAST semantic features.

Enhances search queries by:

- Extracting semantic features from results
- Adding cross-language synonyms
- Expanding with related constructs
- Building semantic context

## Examples

    # Basic expansion
    QueryExpansion.expand("find map function")
    # => "find map function collection transform iterate"

    # Context-aware expansion
    QueryExpansion.expand("debug error", intent: :debug)
    # => "debug error exception failure bug issue problem"

## Summary

### Functions

enrich_query(query, features, opts \\ [])

Build an enriched query from original query + result features.

expand(query, opts \\ [])

Expand a query string with semantic features and synonyms.

extract_features_from_results(results)

Extract semantic features from query results to enhance future queries.

suggest_variations(query, opts \\ [])

Suggest query variations based on semantic analysis.

## Functions

# enrich_query(query, features, opts \\ [])

    @spec enrich_query(String.t(), [String.t()], keyword()) :: String.t()

Build an enriched query from original query + result features.

Useful for iterative search refinement.

## Examples

    results = [...]  # Initial search results
    features = QueryExpansion.extract_features_from_results(results)

    QueryExpansion.enrich_query("map function", features, max_features: 3)
    # => "map function collection transform iterate"

# expand(query, opts \\ [])

    @spec expand(
      String.t(),
      keyword()
    ) :: String.t()

Expand a query string with semantic features and synonyms.

## Options

- `:intent` - Query intent (`:explain`, `:refactor`, `:example`, `:debug`) (default: auto-detect)
- `:include_synonyms` - Include semantic synonyms (default: true)
- `:include_cross_language` - Include cross-language terms (default: true)
- `:max_terms` - Maximum expansion terms to add (default: 5)

## Examples

    QueryExpansion.expand("map over list")
    # => "map over list collection iterate transform apply"

    QueryExpansion.expand("fix bug", intent: :debug)
    # => "fix bug error exception failure issue problem"

# extract_features_from_results(results)

    @spec extract_features_from_results([map()]) :: [String.t()]

Extract semantic features from query results to enhance future queries.

Analyzes MetaAST metadata from results to build a semantic feature set that can be used for query refinement.

## Examples

    results = [%{meta_ast: {:collection_op, :map, ...}}, ...]

    QueryExpansion.extract_features_from_results(results)
    # => ["collection", "map", "transform", "iteration", "apply"]

# suggest_variations(query, opts \\ [])

    @spec suggest_variations(
      String.t(),
      keyword()
    ) :: [String.t()]

Suggest query variations based on semantic analysis.

Returns alternative phrasings that might yield better results.

## Examples

    QueryExpansion.suggest_variations("find map")
    # => [
    #   "find map function",
    #   "find transform operation",
    #   "find collection map",
    #   "find iterate apply"
    # ]