Skip to content

Commit

Permalink
updated file to comply with pr test
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAlAdraaa committed Sep 11, 2024
1 parent 4bd995e commit f298275
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions rag/qdrant_with_reranking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -626,38 +626,40 @@
"reranker = Ranker()\n",
"\n",
"def retrieve_and_rerank(query):\n",
" \"\"\"\n",
" This method takes a query as a string, searches and retrieves\n",
" relevant data from the Qdrant database, and then reranks the\n",
" retrieved data based on relevance, printing the scores in a table.\n",
" \"\"\"\n",
" query_embedded = model.encode(query).tolist()\n",
" \"\"\"\n",
" This method takes a query as a string, searches and retrieves\n",
" relevant data from the Qdrant database, and then reranks the\n",
" retrieved data based on relevance, printing the scores in a table.\n",
" \"\"\"\n",
" query_embedded = model.encode(query).tolist()\n",
"\n",
" search_results = client.search(\n",
" collection_name=\"retrieval with reranking\",\n",
" query_vector=query_embedded,\n",
" limit=5\n",
" )\n",
" search_results = client.search(\n",
" collection_name=\"retrieval with reranking\",\n",
" query_vector=query_embedded,\n",
" limit=5\n",
" )\n",
"\n",
" # convert Qdrant results into a format suitable for re-ranking\n",
" search_texts = [\n",
" {\"text\": result.payload['text']} \n",
" for result in search_results\n",
" ]\n",
" # Convert Qdrant results into a format suitable for re-ranking\n",
" search_texts = [\n",
" {\"text\": result.payload['text']}\n",
" for result in search_results\n",
" ]\n",
"\n",
" re_ranked_results = reranker.rerank(\n",
" RerankRequest(query,search_texts)\n",
" re_ranked_results = reranker.rerank(\n",
" RerankRequest(query, search_texts)\n",
" )\n",
" # Prepare the data for the table\n",
" table_data = [\n",
" (result['score'], result['text']) \n",
" for result in re_ranked_results\n",
" ]\n",
" # print the table\n",
" print(f\"Query: {query}\")\n",
" headers = [\"Re-ranked Score\", \"Text\"]\n",
" print(tabulate(table_data, headers=headers, tablefmt=\"grid\"))\n",
" print(\"\\n\\n\")"
"\n",
" # Prepare the data for the table\n",
" table_data = [\n",
" (result['score'], result['text']) \n",
" for result in re_ranked_results\n",
" ]\n",
"\n",
" # Print the table\n",
" print(f\"Query: {query}\")\n",
" headers = [\"Re-ranked Score\", \"Text\"]\n",
" print(tabulate(table_data, headers=headers, tablefmt=\"grid\"))\n",
" print(\"\\n\\n\")"
]
},
{
Expand Down

0 comments on commit f298275

Please sign in to comment.