opensearch-project / OpenSearch

🔎 Open source distributed and RESTful search engine.
https://opensearch.org/docs/latest/opensearch/index/
Apache License 2.0
9.88k stars 1.84k forks source link

[Feature Request] SearchExtBuilder in SearchResponse #9328

Closed austintlee closed 1 year ago

austintlee commented 1 year ago

Is your feature request related to a problem? Please describe. In conversational search where the result of Retrieval Augmented Generation (RAG) is a single "hit" (answer), I would like a way to include this answer in the search response separately from the search hits.

Describe the solution you'd like As RAG is accomplished via a search pipeline, I would like a solution that makes it easy for users to match a part of the response with the search pipeline that generated the part. SearchRequest already provides this through SearchExtBuilders. Adding support for SearchExtBuilders to SearchResponse will probably solve a number of use cases.

Describe alternatives you've considered For conversational search specifically, a generated answer could be returned as an additional search hit, but this feels hacky and won't generalize to solve other, similar problems that require something in the search response that does not alter SearchHits.

Additional context

6794 also proposes a way to include extra information in SearchResponse.

Sample

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 110,
      "relation": "eq"
    },
    "max_score": 0.55129033,
    "hits": [
      {
       "_index": "...",
        "_id": "...",
        "_score": 0.55129033,
        "_source": {
          "text": "...",
          "title": "..."
        }
      },
      {
      ...
      }
      ...
      {
      ...
      }
    ],
  }, // end of hits
  "ext": {
    "generative_qa": { // a search response processor
      "answer": "..."
    }
  }
} 
austintlee commented 1 year ago

@msfroh Tagging you to get feedback on this change. Is this generally in the right direction? Thanks in advance.

austintlee commented 1 year ago

Can we assign this one to me and remove the 'untriaged' label?

navneet1v commented 1 year ago

@austintlee can you please add a sample response on where this new key will be added in Search Response.

austintlee commented 1 year ago

https://github.com/opensearch-project/OpenSearch/pull/9379#discussion_r1297694637

Note that I fixed the indenting issue in the sample. @navneet1v

navneet1v commented 1 year ago

@austintlee lets add the sample here too. So that we understand what is scope of this issue.

austintlee commented 1 year ago

@austintlee lets add the sample here too. So that we understand what is scope of this issue.

Sample added to the description above. Thanks!

sejli commented 1 year ago

PRs merged into main and 2.x, thanks for the contribution @austintlee! 🎉