Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed duplicate qdrant recreate_collection call to create 'Articles' collection #1719

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
{
"data": {
"text/plain": [
"'vector_database_wikipedia_articles_embedded (10).zip'"
"'vector_database_wikipedia_articles_embedded.zip'"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -508,46 +508,6 @@
")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9f39a8c395554ca3",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-21T23:56:21.577594Z",
"start_time": "2024-05-21T23:56:21.460740Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vector_size = len(article_df['content_vector'][0])\n",
"\n",
"qdrant.recreate_collection(\n",
" collection_name='Articles',\n",
" vectors_config={\n",
" 'title': rest.VectorParams(\n",
" distance=rest.Distance.COSINE,\n",
" size=vector_size,\n",
" ),\n",
" 'content': rest.VectorParams(\n",
" distance=rest.Distance.COSINE,\n",
" size=vector_size,\n",
" ),\n",
" }\n",
")"
]
},
{
"cell_type": "markdown",
"id": "e95be6e0c9af4c21",
Expand All @@ -571,13 +531,13 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Upserting articles: 100%|█████████████████████████████████████████████████████████████████████████████████████| 25000/25000 [02:52<00:00, 144.82it/s]\n"
"Upserting articles: 100%|██████████| 25000/25000 [06:50<00:00, 60.93it/s]\n"
]
}
],
"source": [
"from qdrant_client.models import PointStruct # Import the PointStruct to store the vector and payload\n",
"from tqdm import tqdm # Library to show the progress bar \n",
"from tqdm import tqdm # Library to show the progress bar\n",
"\n",
"# Populate collection with vectors using tqdm to show progress\n",
"for k, v in tqdm(article_df.iterrows(), desc=\"Upserting articles\", total=len(article_df)):\n",
Expand All @@ -587,7 +547,7 @@
" points=[\n",
" PointStruct(\n",
" id=k,\n",
" vector={'title': v['title_vector'], \n",
" vector={'title': v['title_vector'],\n",
" 'content': v['content_vector']},\n",
" payload={\n",
" 'id': v['id'],\n",
Expand Down Expand Up @@ -652,22 +612,21 @@
"outputs": [],
"source": [
"def query_qdrant(query, collection_name, vector_name='title', top_k=20):\n",
"\n",
" # Creates embedding vector from user query\n",
" embedded_query = openai.embeddings.create(\n",
" input=query,\n",
" model=EMBEDDING_MODEL,\n",
" ).data[0].embedding # We take the first embedding from the list\n",
" \n",
"\n",
" query_results = qdrant.search(\n",
" collection_name=collection_name,\n",
" query_vector=(\n",
" vector_name, embedded_query\n",
" ),\n",
" limit=top_k, \n",
" limit=top_k,\n",
" query_filter=None\n",
" )\n",
" \n",
"\n",
" return query_results"
]
},
Expand Down Expand Up @@ -777,12 +736,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
},
"vscode": {
"interpreter": {
"hash": "fd16a328ca3d68029457069b79cb0b38eb39a0f5ccc4fe4473d3047707df8207"
}
"version": "3.13.0"
}
},
"nbformat": 4,
Expand Down