haystack
82 строки · 2.7 Кб
1---
2upgrade:
3- |
4The Opensearch custom query syntax changes: the old filter placeholders for ``custom_query`` are no longer supported.
5Replace your custom filter expressions with the new ``${filters}`` placeholder:
6
7**Old:**
8```python
9retriever = BM25Retriever(
10custom_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
30retriever.retrieve(
31query="What is the meaning of life?",
32filters={"years": [2019, 2020], "quarters": [1, 2, 3], "date": "2019-03-01"}
33)
34```
35
36**New:**
37```python
38retriever = BM25Retriever(
39custom_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
55retriever.retrieve(
56query="What is the meaning of life?",
57filters={"year": [2019, 2020], "quarter": [1, 2, 3], "date": {"$gte": "2019-03-01"}}
58)
59```
60features:
61- |
62When using ``custom_query`` in ``BM25Retriever`` along with ``OpenSearch``
63or ``Elasticsearch``, we added support for dynamic ``filters``, like in regular queries.
64With this change, you can pass filters at query-time without having to modify the ``custom_query``:
65Instead of defining filter expressions and field placeholders, all you have to do
66is setting the ``${filters}`` placeholder analogous to the ``${query}`` placeholder into
67your ``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