-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathwiki.sd
More file actions
107 lines (91 loc) · 2.33 KB
/
wiki.sd
File metadata and controls
107 lines (91 loc) · 2.33 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
schema wiki {
document wiki {
field id type int {
indexing: attribute | summary
}
field title type string {
indexing: index | summary
index: enable-bm25
}
field url type string {
indexing: index | summary
index: enable-bm25
}
field paragraphs type array<string> {
indexing: index | summary
index: enable-bm25 # bm25 computed over all elements (bag of words)
bolding: on
}
}
field paragraph_embeddings type tensor<float>(p{},x[384]) {
indexing {
input paragraphs |
for_each {
(input title || "") . " " . ( _ || "")
} | embed e5 | attribute | index # Index keyword enables HNSW index
}
attribute {
distance-metric: angular #match the E5 embedding model distance metric
}
}
fieldset default {
fields: title, url, paragraphs
}
rank-profile semantic inherits default {
inputs {
query(q) tensor<float>(x[384])
}
first-phase {
expression: cos(distance(field,paragraph_embeddings))
}
match-features {
closest(paragraph_embeddings)
}
}
rank-profile bm25 {
first-phase {
expression: 2*bm25(title) + bm25(paragraphs)
}
}
rank-profile hybrid inherits semantic {
function all_paragraph_similarities() {
expression {
cosine_similarity(query(q),attribute(paragraph_embeddings), x)
}
}
function avg_paragraph_similarities() {
expression {
reduce(cosine_similarity(query(q),attribute(paragraph_embeddings), x), avg, p)
}
}
function keywords() {
expression: bm25(title) + bm25(paragraphs) + bm25(url)
}
function log_bm25() {
expression: if(keywords > 0, log(keywords), 0)
}
first-phase {
expression: cos(distance(field,paragraph_embeddings))
}
second-phase {
expression {
firstPhase + log_bm25 + 10*cos(distance(field,paragraph_embeddings))
}
}
match-features {
firstPhase
closest(paragraph_embeddings)
bm25(title)
bm25(paragraphs)
bm25(url)
log_bm25
avg_paragraph_similarities
all_paragraph_similarities
}
}
document-summary minimal {
summary id {}
summary title {}
}
}