Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add option to return latency each feature adds to a query during feature logging #30

Open
adamjq opened this issue Feb 14, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@adamjq
Copy link

adamjq commented Feb 14, 2024

Is your feature request related to a problem?

As a developer, I want to be able to debug the latency each feature adds to a query during feature logging.

This would help identify features which have an outsized impact on latency.

What solution would you like?

Note - the queries below are taken from a POC repo I created here.

Add a field similar to "time_in_nanos" to the feature logs in the SLTR query response when "profile": true, e.g.

"log_entry1": [
    {
      "name": "title_query",
      "value": 0.5442147,
      "time_in_nanos": 1020
    },

Request

GET http://localhost:9200/movies/_search
Content-Type: application/json

{
  "profile": true,  
  "query": {
      "bool": {
        "must": { 
            "match": {
                "title": "First"
            }
        },
        "filter" : [
            {
                "sltr" : {
                    "featureset" : "moviefeatureset",
                    "_name": "logged_featureset",
                    "active_features" : [ 
                        "title_query",
                        "description_query"
                    ],
                    "params": {
                        "query_text": "First"
                    }
                }
            }
        ]
      }
  },
  "ext": {
        "ltr_log": {
            "log_specs": {
                "name": "log_entry1",
                "named_query": "logged_featureset"
            }
        }
    }
}

Response:

{
  "took": 14,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 0.5442147,
    "hits": [
      {
        "_index": "movies",
        "_id": "5lp2qY0BRnj6a9Pt_aCl",
        "_score": 0.5442147,
        "_source": {
          "title": "First Blood",
          "description": "First Blood is a 1982 American-Canadian action directed by Ted Kotcheff and co-written by and starring Sylvester Stallone as Vietnam War veteran John Rambo.",
          "year_released": 1982
        },
        "fields": {
          "_ltrlog": [
            {
              "log_entry1": [
                {
                  "name": "title_query",
                  "value": 0.5442147,
                  "time_in_nanos": 1020
                },
                {
                  "name": "description_query",
                  "value": 0.95960927,
                  "time_in_nanos": 8390
                }
              ]
            }
          ]
        },
        "matched_queries": [
          "logged_featureset"
        ]
      },
      {
        "_index": "movies",
        "_id": "6Fp3qY0BRnj6a9PtEaB7",
        "_score": 0.36928856,
        "_source": {
          "title": "Rambo: First Blood Part II",
          "description": "Rambo returns to the jungles of Vietnam on a mission to infiltrate an enemy base-camp and rescue the American POWs still held captive there.",
          "year_released": 1985
        },
        "fields": {
          "_ltrlog": [
            {
              "log_entry1": [
                {
                  "name": "title_query",
                  "value": 0.36928856,
                  "time_in_nanos": 3458
                },
                {
                  "name": "description_query"
                }
              ]
            }
          ]
        },
        "matched_queries": [
          "logged_featureset"
        ]
      }
    ]
  },
  "profile": {
    "shards": [
      {
        "id": "[a1wUq5DZToSLGmTEL04JXA][movies][0]",
        "inbound_network_time_in_millis": 0,
        "outbound_network_time_in_millis": 0,
        "searches": [
          {
            "query": [
              {
                "type": "BooleanQuery",
                "description": "+title:first #rankerquery:",
                "time_in_nanos": 346376,
                "breakdown": {
                  "set_min_competitive_score_count": 0,
                  "match_count": 0,
                  "shallow_advance_count": 0,
                  "set_min_competitive_score": 0,
                  "next_doc": 3000,
                  "match": 0,
                  "next_doc_count": 2,
                  "score_count": 2,
                  "compute_max_score_count": 0,
                  "compute_max_score": 0,
                  "advance": 5167,
                  "advance_count": 2,
                  "score": 4209,
                  "build_scorer_count": 5,
                  "create_weight": 195042,
                  "shallow_advance": 0,
                  "create_weight_count": 1,
                  "build_scorer": 138958
                },
                "children": [
                  {
                    "type": "TermQuery",
                    "description": "title:first",
                    "time_in_nanos": 231458,
                    "breakdown": {
                      "set_min_competitive_score_count": 0,
                      "match_count": 0,
                      "shallow_advance_count": 0,
                      "set_min_competitive_score": 0,
                      "next_doc": 0,
                      "match": 0,
                      "next_doc_count": 0,
                      "score_count": 2,
                      "compute_max_score_count": 0,
                      "compute_max_score": 0,
                      "advance": 3666,
                      "advance_count": 4,
                      "score": 2500,
                      "build_scorer_count": 7,
                      "create_weight": 178500,
                      "shallow_advance": 0,
                      "create_weight_count": 1,
                      "build_scorer": 46792
                    }
                  },
                  {
                    "type": "RankerQuery",
                    "description": "rankerquery:",
                    "time_in_nanos": 9624,
                    "breakdown": {
                      "set_min_competitive_score_count": 0,
                      "match_count": 0,
                      "shallow_advance_count": 0,
                      "set_min_competitive_score": 0,
                      "next_doc": 667,
                      "match": 0,
                      "next_doc_count": 2,
                      "score_count": 0,
                      "compute_max_score_count": 0,
                      "compute_max_score": 0,
                      "advance": 583,
                      "advance_count": 2,
                      "score": 0,
                      "build_scorer_count": 6,
                      "create_weight": 1625,
                      "shallow_advance": 0,
                      "create_weight_count": 1,
                      "build_scorer": 6749
                    }
                  }
                ]
              }
            ],
            "rewrite_time": 76125,
            "collector": [
              {
                "name": "SimpleTopScoreDocCollector",
                "reason": "search_top_hits",
                "time_in_nanos": 14374
              }
            ]
          }
        ],
        "aggregations": []
      }
    ]
  }
}

What alternatives have you considered?

This feature could also be implemented via an SLTR query parameter instead of through the profile API setting.

Do you have any additional context?

Please let me know if there are alternative ways to debug the latency each feature adds to a query during feature logging already using the plugin, as I couldn't find any references in the official documentation

@adamjq adamjq added enhancement New feature or request untriaged labels Feb 14, 2024
@adamjq adamjq changed the title [FEATURE] [FEATURE] Add option to return latency each feature adds to a query during feature logging Feb 14, 2024
@rishabhmaurya
Copy link

@noCharger Could you please take a look if this can be supported via LTR plugin, thanks.

@adamjq
Copy link
Author

adamjq commented Mar 6, 2024

Thanks @noCharger. If you have any tips on how to profile latency for feature logging that would be great to hear too

@noCharger
Copy link

@adamjq By convention, I believe the profile API will include latency in the profile field rather than the hits field. If we want to record the logging, can we create a logging schema that includes both necessary and optional fields?

@noCharger noCharger removed their assignment May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🆕 New
Development

No branches or pull requests

4 participants