{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63618e8d-78f9-4187-b00e-4ed59176b06c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import torch\n",
    "import pandas as pd\n",
    "from sentence_transformers import SentenceTransformer\n",
    "\n",
    "\n",
    "torch.set_num_threads(os.cpu_count())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03f98e48-eded-4486-85ce-a84ea1341d20",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = SentenceTransformer('embedding')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fecdf653-728f-4a96-8b79-15d2659ad3b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('corpus/rerank.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58bb9a1c-9b11-4912-a271-98bd0b5bf5f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['idx'] = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc8738d5-db41-4486-b819-cdda83708159",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['vector'] = list(model.encode(('[QRY]'+df['query']).to_list()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "022e1b1c-59bc-4ee4-ba24-89ec392e5319",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_pickle('corpus/rerank.pkl')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
