haystack

Форк
0
/
custom-query-dynamic-filters-dd83ec358d2f64a6.yaml 
82 строки · 2.7 Кб
1
---
2
upgrade:
3
  - |
4
    The Opensearch custom query syntax changes: the old filter placeholders for ``custom_query`` are no longer supported.
5
    Replace your custom filter expressions with the new ``${filters}`` placeholder:
6

7
    **Old:**
8
    ```python
9
      retriever = BM25Retriever(
10
        custom_query="""
11
          {
12
              "query": {
13
                  "bool": {
14
                      "should": [{"multi_match": {
15
                          "query": ${query},
16
                          "type": "most_fields",
17
                          "fields": ["content", "title"]}}
18
                      ],
19
                      "filter": [
20
                          {"terms": {"year": ${years}}},
21
                          {"terms": {"quarter": ${quarters}}},
22
                          {"range": {"date": {"gte": ${date}}}}
23
                      ]
24
                  }
25
              }
26
          }
27
        """
28
      )
29

30
      retriever.retrieve(
31
          query="What is the meaning of life?",
32
          filters={"years": [2019, 2020], "quarters": [1, 2, 3], "date": "2019-03-01"}
33
      )
34
    ```
35

36
    **New:**
37
    ```python
38
      retriever = BM25Retriever(
39
        custom_query="""
40
          {
41
              "query": {
42
                  "bool": {
43
                      "should": [{"multi_match": {
44
                          "query": ${query},
45
                          "type": "most_fields",
46
                          "fields": ["content", "title"]}}
47
                      ],
48
                      "filter": ${filters}
49
                  }
50
              }
51
          }
52
        """
53
      )
54

55
      retriever.retrieve(
56
          query="What is the meaning of life?",
57
          filters={"year": [2019, 2020], "quarter": [1, 2, 3], "date": {"$gte": "2019-03-01"}}
58
      )
59
    ```
60
features:
61
  - |
62
    When using ``custom_query`` in ``BM25Retriever`` along with ``OpenSearch``
63
    or ``Elasticsearch``, we added support for dynamic ``filters``, like in regular queries.
64
    With this change, you can pass filters at query-time without having to modify the ``custom_query``:
65
    Instead of defining filter expressions and field placeholders, all you have to do
66
    is setting the ``${filters}`` placeholder analogous to the ``${query}`` placeholder into
67
    your ``custom_query``.
68
    **For example:**
69
    ```python
70
      {
71
          "query": {
72
              "bool": {
73
                  "should": [{"multi_match": {
74
                      "query": ${query},                 // mandatory query placeholder
75
                      "type": "most_fields",
76
                      "fields": ["content", "title"]}}
77
                  ],
78
                  "filter": ${filters}                 // optional filters placeholder
79
              }
80
          }
81
      }
82
    ```
83

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.