-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit of ch5 sample app for labs (to be completed during the…
… lab)
- Loading branch information
1 parent
266576e
commit 3031635
Showing
6 changed files
with
1,216 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
examples/training-artifacts/101/ch5/embedder_rrf_rag/.vespaignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This file excludes unnecessary files from the application package. See | ||
# https://docs.vespa.ai/en/reference/vespaignore.html for more information. | ||
.DS_Store | ||
.gitignore | ||
README.md | ||
ext/ |
1,000 changes: 1,000 additions & 0 deletions
1,000
examples/training-artifacts/101/ch5/embedder_rrf_rag/ext/vespa_feed-1K_no_embeddings.jsonl
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
examples/training-artifacts/101/ch5/embedder_rrf_rag/remove_embeddings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import json | ||
|
||
INPUT_FILE="ext/vespa_feed-1K.jsonl" | ||
OUTPUT_FILE="ext/vespa_feed-1K_no_embeddings.jsonl" | ||
|
||
# example line in the input file | ||
# {"put": "id:product:product::Amazon_Fashion987231", "fields": {"id": 987231, "title": "CENTER Rabbit Party Hats Christmas Hats for Adults Bunny Hat Rabbit Ears Mobile Jumping Cap Fun Hat", "category": "Amazon_Fashion", "description": "", "price": 3100, "average_rating": 4.5, "embedding": [0.008706144988536835, 0.00692428182810545, 0.05008220300078392, -0.03883737325668335, -0.019708802923560143, 0.018436191603541374, -0.0037979180924594402, -0.04086985066533089, 0.02285926789045334, 0.022953731939196587, -0.03295670449733734, 0.01725703477859497, -0.00434730714187026, 0.036510489881038666, 0.012212918139994144, 0.007266075350344181, 0.05195595696568489, -0.003304088255390525, -0.14710889756679535, -0.01000181119889021, -0.02274658903479576, 0.04104312136769295, -0.0063829622231423855, 0.008590606041252613, -0.08836144953966141, -0.046636927872896194, -0.041007012128829956, -0.016355542466044426, -0.06989160925149918, -0.16165342926979065, -0.01774388924241066, 0.061450887471437454, -0.0012792986817657948, -0.0554032139480114, 0.041376326233148575, -0.02904839813709259, -0.013520227745175362, 0.04547768458724022, -0.018820643424987793, 0.019787374883890152, -0.022068357095122337, 0.03599236533045769, -0.018523745238780975, 0.013314939104020596, 0.013508589938282967, -0.03554629161953926, -0.015464741736650467, -0.02142908424139023, -0.04987680912017822, 0.03025384433567524, 0.03577601537108421, -0.04736088961362839, -0.02799147553741932, 0.027797596529126167, -0.006664808373898268, 0.05156460031867027, -0.003613585839048028, -0.04917958006262779, 0.045042458921670914, 0.042012769728899, -0.004005409311503172, 0.032016173005104065, -0.3252218961715698, 0.007479398977011442, 0.10389310121536255, -0.03255470097064972, -0.010276103392243385, -0.07720757275819778, -0.019704870879650116, -0.03134865686297417, 0.04496806859970093, -0.03675314784049988, -0.07906031608581543, 0.0700363740324974, 0.025187470018863678, -0.04756070300936699, 0.03532344102859497, 0.022915568202733994, 0.02770422212779522, 0.005796818993985653, -0.0692094936966896, 0.036571748554706573, 0.033657461404800415, -0.010338487103581429, 0.006327977869659662, 0.008825878612697124, -0.08306542783975601, -0.018297895789146423, -0.01921265386044979, 0.029224185273051262, -0.03989935293793678, -0.0637538954615593, 0.047146979719400406, -0.009665398858487606, -0.0600600391626358, 0.000532992766238749, 0.01686021313071251, 0.01957589201629162, 0.028927208855748177, 0.26286906003952026, 0.05114250257611275, 0.01927117444574833, 0.06915844976902008, -0.06090870499610901, 0.02024815045297146, -0.011619863100349903, -0.00921551138162613, -0.037105027586221695, -0.02271914668381214, -0.03877798467874527, 0.004896149039268494, -0.024964015930891037, 0.028943587094545364, 0.05048946291208267, -0.01663758046925068, 0.033312827348709106, -0.06477384269237518, 0.04207960143685341, 0.009631498716771603, 0.054988496005535126, -0.009936699643731117, -0.02934136800467968, -0.005706857889890671, 0.02879279851913452, -0.024603044614195824, 0.06427661329507828, -0.04814275726675987, 0.033614758402109146, -0.003578218864277005, 0.06231331825256348, 0.053646259009838104, -0.027055010199546814, -0.040031302720308304, 0.008879979141056538, -0.0320250429213047, 0.0030703917145729065, 0.06213577091693878, -0.04087560251355171, 0.007726105861365795, -0.055797725915908813, -0.026008576154708862, -0.08720946311950684, 0.13266360759735107, -0.03377920761704445, 0.025685904547572136, 0.05116606876254082, 0.033553704619407654, -0.02549905888736248, -0.03497730568051338, -0.004051984753459692, -0.015362762846052647, -0.007113694678992033, 0.025945236906409264, 0.048846080899238586, 0.03277842700481415, 0.0020529567264020443, 0.026446614414453506, 0.00017094964277930558, 0.008108239620923996, 0.023480547592043877, -0.009028516709804535, 0.04641536995768547, 0.02659882791340351, 0.08923326432704926, 0.03590584546327591, 0.0032831402495503426, 0.030130065977573395, 0.0019924382213503122, 0.055002979934215546, -0.012834412045776844, 0.02451755851507187, -0.0007795696146786213, 0.030950674787163734, 0.0358232706785202, 0.03862854093313217, -0.03138338029384613, -0.05192343145608902, 0.0330805629491806, 0.0673980712890625, -0.012659487314522266, 0.0341675840318203, 0.041247542947530746, -0.04121901094913483, 0.0033833906054496765, 0.011330662295222282, -0.0012147005181759596, -0.00838866364210844, -0.012355624698102474, 0.08863667398691177, 0.07716961205005646, -0.03360581025481224, 0.09616091102361679, -0.009030207060277462, -0.01509299036115408, 0.039576008915901184, 0.01091804914176464, -0.007640980649739504, -0.0021026721224188805, 0.10281151533126831, 0.00550538394600153, -0.061592888087034225, -0.08850890398025513, 0.0019816725980490446, -0.022194867953658104, -0.02397960238158703, -0.02136954851448536, 0.061716772615909576, -0.05318624898791313, 0.03867899253964424, -0.043909505009651184, 0.022600723430514336, -0.005250596906989813, 0.012496613897383213, 0.007864202372729778, 0.013829711824655533, 0.054033905267715454, -0.05887710675597191, -0.03665275126695633, 0.10208489745855331, 0.034644223749637604, -0.01355815026909113, 0.047204114496707916, -0.08863551914691925, -0.062089066952466965, 0.0377037487924099, 0.029051538556814194, -0.0676615834236145, -0.0495169423520565, -0.0025997627526521683, -0.015497041866183281, 0.027948834002017975, 0.026585044339299202, -0.0001117005231208168, 0.015683680772781372, 0.04765588045120239, 0.04558475688099861, -0.0683441162109375, 0.09909594804048538, 0.06924088299274445, -0.020922422409057617, 0.07137149572372437, 0.06914512813091278, 0.0004654295917134732, 0.0006155205192044377, 0.05013982206583023, -0.008206715807318687, 0.012833538465201855, -0.027573293074965477, -0.020055292174220085, 0.11351202428340912, 0.06481759995222092, -0.016648096963763237, 0.07227921485900879, -0.04866008460521698, -0.06044692173600197, 0.009577332064509392, -0.12307132035493851, -0.06041284278035164, -0.09283484518527985, 0.0684569776058197, -0.05876143276691437, -0.017231300473213196, 0.05901489779353142, -0.03168278932571411, -0.03415185585618019, -0.035074397921562195, -0.03508756682276726, 0.028621479868888855, 0.004046149551868439, -0.06223214045166969, 0.029768256470561028, 0.07121822983026505, -0.0807047039270401, -0.003811284201219678, 0.017350608482956886, -0.07254483550786972, 0.006139929872006178, 0.009430719539523125, 0.004797095432877541, 0.02165779285132885, -0.03909679129719734, -0.00018235236348118633, 0.015281707048416138, 0.011002296581864357, -0.0297059565782547, -0.06312386691570282, -0.06425154954195023, 0.007476987782865763, -0.033913422375917435, 0.020751753821969032, -0.021488163620233536, -0.030984021723270416, 0.00017515744548290968, 0.03424718603491783, 0.1250126212835312, 0.040066320449113846, 0.032705262303352356, 0.01738573983311653, -0.06829874217510223, -0.005760081112384796, -0.038384370505809784, 0.0471683032810688, -0.0015863036969676614, -0.03653369098901749, -0.10192476958036423, -0.03615661710500717, 0.017195235937833786, -0.002114292001351714, -0.04694288223981857, -0.002901688916608691, 0.03571411967277527, -0.05279149115085602, 0.011374074965715408, 0.03268689662218094, 0.07431381195783615, -0.03512423112988472, 0.01947258599102497, 0.09415441006422043, -0.014486253261566162, -0.1739281862974167, 0.0061887106858193874, 0.050733618438243866, 0.027430757880210876, -0.01607842743396759, -0.022376051172614098, 0.04357682168483734, -0.013782617636024952, 0.04539542272686958, -0.03713028505444527, 0.11902302503585815, 0.06996756792068481, 0.008093839511275291, -0.0006383286672644317, 0.0562027171254158, 0.11619176715612411, -0.0226733461022377, 0.0617365762591362, -0.04312478005886078, -0.10622943192720413, -0.04948030039668083, 0.02064296416938305, 0.12321510910987854, 0.02398318611085415, 0.016510913148522377, -0.08735989034175873, -0.0568554550409317, -0.04826837778091431, -0.09825190901756287, 0.020976798608899117, 0.03494398668408394, -0.04270603507757187, 0.053369276225566864, -0.03290951997041702, -0.023407621309161186, 0.0775999054312706, 0.0036593987606465816, -0.03759728744626045, -0.02757558785378933, -0.03483259677886963, 0.09047453105449677, 0.025219948962330818, 0.0003041496966034174, -0.013868129812180996, 0.019186925143003464, 0.012566504068672657, -0.021956535056233406, 0.022478286176919937, -0.013959426432847977, 0.011458453722298145, -0.015075542032718658, -0.015454597771167755, -0.02492937631905079, 0.03184414282441139, 0.005038146860897541, 0.03293119743466377, 0.00962645374238491, 0.008445682004094124, 0.05854005366563797, 0.05876512452960014, 0.05177081376314163, -0.07067439705133438, -0.04049496725201607, -0.07568228244781494, -0.024374980479478836]}} | ||
|
||
# remove the "embedding" field from each line | ||
with open(INPUT_FILE, "r") as input_file: | ||
with open(OUTPUT_FILE, "w") as output_file: | ||
for line in input_file: | ||
line_dict = json.loads(line) | ||
del line_dict["fields"]["embedding"] | ||
output_file.write(json.dumps(line_dict) + "\n") |
78 changes: 78 additions & 0 deletions
78
examples/training-artifacts/101/ch5/embedder_rrf_rag/schemas/product.sd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
schema product { | ||
|
||
document product { | ||
|
||
field id type int { | ||
indexing: attribute | summary | ||
} | ||
|
||
field title type string { | ||
indexing: index | summary | ||
index: enable-bm25 | ||
} | ||
|
||
field description type string { | ||
indexing: index | summary | ||
index: enable-bm25 | ||
} | ||
|
||
field category type string { | ||
indexing: attribute | summary | ||
attribute: fast-search | ||
match: word | ||
rank: filter | ||
} | ||
|
||
field price type int { | ||
indexing: attribute | summary | ||
} | ||
|
||
field average_rating type float { | ||
indexing: attribute | summary | ||
} | ||
|
||
} | ||
|
||
# TODO define your "embedding" field here, because it will be "artificially" | ||
# generated from existing fields | ||
|
||
fieldset default { | ||
fields: title, description | ||
} | ||
|
||
# semantic search rank profile. Refer to it in your query by adding: | ||
# "ranking.profile": "closeness" | ||
rank-profile closeness { | ||
inputs { | ||
query(q_embedding) tensor<float>(x[384]) | ||
} | ||
first-phase { | ||
expression: closeness(field, embedding) | ||
} | ||
} | ||
|
||
# TODO hybrid search rank profile | ||
# make sure to refer to it in the query | ||
# | ||
# rank-profile rrf inherits closeness { | ||
# function best_bm25() { | ||
# expression: max(bm25(title), bm25(description)) | ||
# } | ||
# global-phase { | ||
# # TODO: you have a closeness() function inherited and a best_bm25() function defined here | ||
# # now define the reciprocal rank fusion expression | ||
# rerank-count: 200 | ||
# } | ||
# } | ||
|
||
document-summary minimal { | ||
summary id {} | ||
} | ||
|
||
document-summary medium { | ||
summary id {} | ||
summary title {} | ||
summary description {} | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
examples/training-artifacts/101/ch5/embedder_rrf_rag/services.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
|
||
<services version="1.0" xmlns:deploy="vespa" xmlns:preprocess="properties" minimum-required-vespa-version="8.338.38"> | ||
|
||
<!-- See https://docs.vespa.ai/en/reference/services-container.html --> | ||
<container id="default" version="1.0"> | ||
|
||
<clients> | ||
<!-- | ||
Required for mTLS to still work, the below | ||
configuration is equivalent to using a single | ||
security/clients.pem | ||
--> | ||
<client id="mtls" permissions="read,write"> | ||
<certificate file="security/clients.pem"/> | ||
</client> | ||
</clients> | ||
|
||
<!-- See https://docs.vespa.ai/en/embedding.html#huggingface-embedder --> | ||
<!-- TODO --> | ||
|
||
<!-- Setup the client to OpenAI --> | ||
<!-- TODO --> | ||
|
||
<!-- | ||
<document-api> tells the container that it should accept documents for indexing. Through the | ||
Document REST API you can PUT new documents, UPDATE existing documents, and DELETE documents | ||
already in the cluster. | ||
Documents sent to the Document REST API will be passed through document processors on the way | ||
to the content cluster. | ||
See: | ||
- Reference: https://docs.vespa.ai/en/reference/services-container.html#document-api | ||
- Operations: https://docs.vespa.ai/en/document-v1-api-guide.html | ||
--> | ||
<document-api/> | ||
|
||
<!-- | ||
<search> tells the container to answers queries and serve results for those queries. | ||
Inside the <search /> cluster you can configure chains of "searchers" - | ||
Java components processing the query and/or result. | ||
See: | ||
- Reference: https://docs.vespa.ai/en/query-api.html | ||
- Searchers: https://docs.vespa.ai/en/searcher-development.html | ||
--> | ||
<search/> <!-- TODO in here, define a search chain pointing to your OpenAI client --> | ||
|
||
<!-- | ||
<nodes> specifies the nodes that should run this cluster. | ||
--> | ||
<nodes> | ||
<node hostalias="node1" /> | ||
</nodes> | ||
|
||
</container> | ||
|
||
<!-- See https://docs.vespa.ai/en/reference/services-content.html --> | ||
<content id="text" version="1.0"> | ||
<min-redundancy>2</min-redundancy> | ||
<documents> | ||
<document type="product" mode="index" /> | ||
</documents> | ||
<nodes> | ||
<node hostalias="node1" distribution-key="0" /> | ||
</nodes> | ||
</content> | ||
|
||
</services> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
### did we successfully feed? | ||
curl -H "Content-Type:application/json" https://e6384e36.c4ba1d52.z.vespa-app.cloud/search/ -d '{ | ||
"yql": "select * from product where true", | ||
"presentation.summary": "medium" | ||
}' | ||
|
||
### ANN | ||
curl -H "Content-Type:application/json" https://e6384e36.c4ba1d52.z.vespa-app.cloud/search/ -d '{ | ||
"yql": "select * from product where ({targetHits:100}nearestNeighbor(embedding,q_embedding))", | ||
"ranking.profile": "closeness", | ||
"presentation.summary": "medium", | ||
"query_text": "Mini Stencil", | ||
"input.query(q_embedding)": "embed(@query_text)" | ||
}' | ||
|
||
|
||
### RRF | ||
curl -H "Content-Type:application/json" https://e6384e36.c4ba1d52.z.vespa-app.cloud/search/ -d '{ | ||
"yql": "select * from product where title contains @query_text OR ({targetHits:100}nearestNeighbor(embedding,q_embedding))", | ||
"ranking.profile": "rrf", | ||
"presentation.summary": "medium", | ||
"query_text": "Mini Stencil", | ||
"input.query(q_embedding)": "embed(@query_text)" | ||
}' | ||
|
||
### OpenAI command | ||
vespa query \ | ||
--timeout 60 \ | ||
--header="X-LLM-API-KEY:insert-api-key-here" \ | ||
query="what kind of mini stencils do you have for sale?" \ | ||
hits=5 \ | ||
searchChain=openai \ | ||
format=sse \ | ||
traceLevel=1 | ||
|
||
### OpenAI HTTP command. The response comes back as a stream | ||
curl -H "Content-Type:application/json" -H "X-LLM-API-KEY:insert-api-key-here" https://e6384e36.c4ba1d52.z.vespa-app.cloud/search/ -d '{ | ||
"yql": "select * from product where title contains @query_text OR ({targetHits:100}nearestNeighbor(embedding,q_embedding))", | ||
"ranking.profile": "rrf", | ||
"presentation.summary": "medium", | ||
"query_text": "Mini Stencil", | ||
"input.query(q_embedding)": "embed(@query_text)", | ||
"query": "what kind of mini stencils do you have for sale?", | ||
"searchChain": "openai", | ||
"format": "sse", | ||
"traceLevel": 0 | ||
}' |