1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/eval/eval/tensor_function.h>
namespace vespalib::eval {
/**
* Tensor function combining multiple dot products with multiple
* layers of aggregation, resulting in a single scalar result.
*
* inputs:
* query: tensor<float>(qt{},x[32])
* document: tensor<float>(dt{},x[32])
*
* expression:
* reduce(
* reduce(
* reduce(query * document, sum, x),
* max, dt
* ),
* sum, qt
* )
*
* Both query and document contains a collection of vectors. For each
* query vector, take the dot product with all document vectors and
* select the maximum result. Sum these partial results into the final
* result value.
*
* Note that not all equivalent forms are matched by this function
* (initial matching will be very specific).
**/
class SumMaxDotProductFunction : public tensor_function::Op2
{
private:
size_t _dp_size;
public:
SumMaxDotProductFunction(const ValueType &res_type_in,
const TensorFunction &query,
const TensorFunction &document,
size_t dp_size);
InterpretedFunction::Instruction compile_self(const CTFContext &ctx) const override;
size_t dp_size() const { return _dp_size; }
bool result_is_mutable() const override { return true; }
static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash);
};
} // namespace
|