"
],
"text/plain": [
" _id question \\\n",
"0 11 Who won Super Bowl 50? \n",
"1 24 Who won Super Bowl 50? \n",
"2 3 Which NFL team won Super Bowl 50? \n",
"3 55 Who was the Super Bowl 50 MVP? \n",
"4 26 Which team won Super Bowl 50. \n",
"\n",
" answers \\\n",
"0 {'answer_start': [177, 177, 177], 'text': ['De... \n",
"1 {'answer_start': [177, 177, 177], 'text': ['De... \n",
"2 {'answer_start': [177, 177, 177], 'text': ['De... \n",
"3 {'answer_start': [248, 248, 252], 'text': ['Vo... \n",
"4 {'answer_start': [177, 177, 177], 'text': ['De... \n",
"\n",
" context \\\n",
"0 Super Bowl 50 was an American football game to... \n",
"1 Super Bowl 50 was an American football game to... \n",
"2 Super Bowl 50 was an American football game to... \n",
"3 The Broncos took an early lead in Super Bowl 5... \n",
"4 Super Bowl 50 was an American football game to... \n",
"\n",
" insert_date_ id title \\\n",
"0 2020-10-02T07:47:06.947313 56beace93aeaaa14008c91df Super_Bowl_50 \n",
"1 2020-10-02T07:47:07.285182 56d20362e7d4791d009025eb Super_Bowl_50 \n",
"2 2020-10-02T07:47:06.946694 56be4db0acb8001400a502ef Super_Bowl_50 \n",
"3 2020-10-02T07:47:07.759154 56be4eafacb8001400a50302 Super_Bowl_50 \n",
"4 2020-10-02T07:47:07.285403 56d600e31c85041400946eb0 Super_Bowl_50 \n",
"\n",
" _search_score \n",
"0 0.798744 \n",
"1 0.798744 \n",
"2 0.763209 \n",
"3 0.754090 \n",
"4 0.742759 "
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#4. search\n",
"search_results = vi_client.search(collection_name, \n",
" text_encoder.encode('who was the winner for nfl fifty'), \n",
" 'question_vector_', page_size=5)\n",
"\n",
"#4.2 first result is the query text itself\n",
"vi_client.results_to_df(search_results)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
_id
\n",
"
question
\n",
"
answers
\n",
"
context
\n",
"
insert_date_
\n",
"
id
\n",
"
title
\n",
"
_search_score
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
50
\n",
"
Who did Denver beat in the 2015 AFC Championsh...
\n",
"
{'answer_start': [372, 368, 372], 'text': ['Ne...
\n",
"
The Panthers finished the regular season with ...
\n",
"
2020-10-02T07:47:07.758767
\n",
"
56d6017d1c85041400946ec1
\n",
"
Super_Bowl_50
\n",
"
1.000000
\n",
"
\n",
"
\n",
"
1
\n",
"
48
\n",
"
Who did Denver beat in the AFC championship?
\n",
"
{'answer_start': [372, 368, 372], 'text': ['Ne...
\n",
"
The Panthers finished the regular season with ...
\n",
"
2020-10-02T07:47:07.758541
\n",
"
56d2045de7d4791d009025f6
\n",
"
Super_Bowl_50
\n",
"
0.960072
\n",
"
\n",
"
\n",
"
2
\n",
"
331
\n",
"
Who did the Broncos beat to win their division...
\n",
"
{'answer_start': [25, 25, 36], 'text': ['Pitts...
\n",
"
The Broncos defeated the Pittsburgh Steelers i...
\n",
"
2020-10-02T07:47:12.209038
\n",
"
56d99f99dc89441400fdb628
\n",
"
Super_Bowl_50
\n",
"
0.923735
\n",
"
\n",
"
\n",
"
3
\n",
"
330
\n",
"
Who did the Broncos defeat in the AFC Champion...
\n",
"
{'answer_start': [192, 192, 204], 'text': ['Ne...
\n",
"
The Broncos defeated the Pittsburgh Steelers i...
\n",
"
2020-10-02T07:47:12.208876
\n",
"
56d7018a0d65d214001982c5
\n",
"
Super_Bowl_50
\n",
"
0.915792
\n",
"
\n",
"
\n",
"
4
\n",
"
328
\n",
"
Who did the Broncos beat in the divisional game?
\n",
"
{'answer_start': [25, 21, 36], 'text': ['Pitts...
\n",
"
The Broncos defeated the Pittsburgh Steelers i...
\n",
"
2020-10-02T07:47:11.956089
\n",
"
56d7018a0d65d214001982c2
\n",
"
Super_Bowl_50
\n",
"
0.906187
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" _id question \\\n",
"0 50 Who did Denver beat in the 2015 AFC Championsh... \n",
"1 48 Who did Denver beat in the AFC championship? \n",
"2 331 Who did the Broncos beat to win their division... \n",
"3 330 Who did the Broncos defeat in the AFC Champion... \n",
"4 328 Who did the Broncos beat in the divisional game? \n",
"\n",
" answers \\\n",
"0 {'answer_start': [372, 368, 372], 'text': ['Ne... \n",
"1 {'answer_start': [372, 368, 372], 'text': ['Ne... \n",
"2 {'answer_start': [25, 25, 36], 'text': ['Pitts... \n",
"3 {'answer_start': [192, 192, 204], 'text': ['Ne... \n",
"4 {'answer_start': [25, 21, 36], 'text': ['Pitts... \n",
"\n",
" context \\\n",
"0 The Panthers finished the regular season with ... \n",
"1 The Panthers finished the regular season with ... \n",
"2 The Broncos defeated the Pittsburgh Steelers i... \n",
"3 The Broncos defeated the Pittsburgh Steelers i... \n",
"4 The Broncos defeated the Pittsburgh Steelers i... \n",
"\n",
" insert_date_ id title \\\n",
"0 2020-10-02T07:47:07.758767 56d6017d1c85041400946ec1 Super_Bowl_50 \n",
"1 2020-10-02T07:47:07.758541 56d2045de7d4791d009025f6 Super_Bowl_50 \n",
"2 2020-10-02T07:47:12.209038 56d99f99dc89441400fdb628 Super_Bowl_50 \n",
"3 2020-10-02T07:47:12.208876 56d7018a0d65d214001982c5 Super_Bowl_50 \n",
"4 2020-10-02T07:47:11.956089 56d7018a0d65d214001982c2 Super_Bowl_50 \n",
"\n",
" _search_score \n",
"0 1.000000 \n",
"1 0.960072 \n",
"2 0.923735 \n",
"3 0.915792 \n",
"4 0.906187 "
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#5 recommendation by id\n",
"search_by_id_results = vi_client.search_by_id(collection_name, documents[50]['_id'], 'question_vector_', page_size=5)\n",
"\n",
"#5.2 first result is the id's text itself\n",
"vi_client.results_to_df(search_by_id_results)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
_id
\n",
"
question
\n",
"
answers
\n",
"
context
\n",
"
insert_date_
\n",
"
id
\n",
"
title
\n",
"
_search_score
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
258
\n",
"
How old was Peyton Manning in 2015?
\n",
"
{'answer_start': [817, 817, 817], 'text': ['39...
\n",
"
Following their loss in the divisional round o...
\n",
"
2020-10-02T07:47:11.000830
\n",
"
56bf301c3aeaaa14008c9550
\n",
"
Super_Bowl_50
\n",
"
0.641220
\n",
"
\n",
"
\n",
"
1
\n",
"
276
\n",
"
How may yards did Peyton Manning throw?
\n",
"
{'answer_start': [77, 77, 77], 'text': ['2,249...
\n",
"
Manning finished the year with a career-low 67...
\n",
"
2020-10-02T07:47:11.239195
\n",
"
56bf38383aeaaa14008c956c
\n",
"
Super_Bowl_50
\n",
"
0.634783
\n",
"
\n",
"
\n",
"
2
\n",
"
270
\n",
"
What was Peyton Manning's passer rating for th...
\n",
"
{'answer_start': [44, 44, 44], 'text': ['67.9'...
\n",
"
Manning finished the year with a career-low 67...
\n",
"
2020-10-02T07:47:11.238646
\n",
"
56beb57b3aeaaa14008c9279
\n",
"
Super_Bowl_50
\n",
"
0.617874
\n",
"
\n",
"
\n",
"
3
\n",
"
252
\n",
"
Who did Peyton Manning play for as a rookie?
\n",
"
{'answer_start': [641, 637, 654], 'text': ['In...
\n",
"
Following their loss in the divisional round o...
\n",
"
2020-10-02T07:47:10.760423
\n",
"
56beb4e43aeaaa14008c9267
\n",
"
Super_Bowl_50
\n",
"
0.612926
\n",
"
\n",
"
\n",
"
4
\n",
"
356
\n",
"
Peyton Manning took how many different teams t...
\n",
"
{'answer_start': [57, 57, 57, 57], 'text': ['t...
\n",
"
Peyton Manning became the first quarterback ev...
\n",
"
2020-10-02T07:47:12.428915
\n",
"
56d704430d65d214001982de
\n",
"
Super_Bowl_50
\n",
"
0.611716
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" _id question \\\n",
"0 258 How old was Peyton Manning in 2015? \n",
"1 276 How may yards did Peyton Manning throw? \n",
"2 270 What was Peyton Manning's passer rating for th... \n",
"3 252 Who did Peyton Manning play for as a rookie? \n",
"4 356 Peyton Manning took how many different teams t... \n",
"\n",
" answers \\\n",
"0 {'answer_start': [817, 817, 817], 'text': ['39... \n",
"1 {'answer_start': [77, 77, 77], 'text': ['2,249... \n",
"2 {'answer_start': [44, 44, 44], 'text': ['67.9'... \n",
"3 {'answer_start': [641, 637, 654], 'text': ['In... \n",
"4 {'answer_start': [57, 57, 57, 57], 'text': ['t... \n",
"\n",
" context \\\n",
"0 Following their loss in the divisional round o... \n",
"1 Manning finished the year with a career-low 67... \n",
"2 Manning finished the year with a career-low 67... \n",
"3 Following their loss in the divisional round o... \n",
"4 Peyton Manning became the first quarterback ev... \n",
"\n",
" insert_date_ id title \\\n",
"0 2020-10-02T07:47:11.000830 56bf301c3aeaaa14008c9550 Super_Bowl_50 \n",
"1 2020-10-02T07:47:11.239195 56bf38383aeaaa14008c956c Super_Bowl_50 \n",
"2 2020-10-02T07:47:11.238646 56beb57b3aeaaa14008c9279 Super_Bowl_50 \n",
"3 2020-10-02T07:47:10.760423 56beb4e43aeaaa14008c9267 Super_Bowl_50 \n",
"4 2020-10-02T07:47:12.428915 56d704430d65d214001982de Super_Bowl_50 \n",
"\n",
" _search_score \n",
"0 0.641220 \n",
"1 0.634783 \n",
"2 0.617874 \n",
"3 0.612926 \n",
"4 0.611716 "
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#6 hybrid search combining traditional and nlp vector search\n",
"search_results = vi_client.hybrid_search(collection_name, 'Peyton Men',\n",
" text_encoder.encode('Peyton Men'),\n",
" ['question_vector_'], ['question'],\n",
" traditional_weight=0.015,\n",
" page_size=5)\n",
"vi_client.results_to_df(search_results)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Edit Metadata",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}