Skip to content

Commit

Permalink
avoid operator overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
levand committed Apr 17, 2023
1 parent d6fd0c6 commit 35f93c2
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 2 deletions.
158 changes: 158 additions & 0 deletions HNSW Failure Demonstration.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "628d5e16",
"metadata": {},
"outputs": [],
"source": [
"import hnswlib\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "f9adbaca",
"metadata": {},
"outputs": [],
"source": [
"index = hnswlib.Index('l2', 2)\n",
"index.init_index(1000)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "cbb66a9f",
"metadata": {},
"outputs": [],
"source": [
"data = np.array([[0.09765625, 0.430419921875],\n",
" [0.20556640625, 0.08978271484375],\n",
" [-0.1527099609375, 0.291748046875],\n",
" [-0.12481689453125, 0.78369140625],\n",
" [0.92724609375, -0.233154296875],\n",
" [0.58349609375, 0.05780029296875],\n",
" [0.1361083984375, 0.85107421875]])\n",
"ids = np.array(range(7))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "4fc982f4",
"metadata": {},
"outputs": [],
"source": [
"index.add_items(data, ids)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "c33471b0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def recall(expected_data):\n",
" missing = 0\n",
" result = index.knn_query(expected_data, k=1)\n",
" for i, id in enumerate(result[0]):\n",
" if id != i:\n",
" missing += 1\n",
" \n",
" return (len(ids) - missing) / len(ids) \n",
" \n",
"recall(data)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "992ed4e6",
"metadata": {},
"outputs": [],
"source": [
"update_data = [[-0.85791015625, -0.82568359375],\n",
" [-0.95947265625, 0.6650390625],\n",
" [0.55615234375, 0.740234375],\n",
" [0.95703125, 0.59814453125],\n",
" [-0.0770263671875, 0.56103515625]]\n",
"update_ids = [4, 2, 3, 5, 6]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "3b07add1",
"metadata": {},
"outputs": [],
"source": [
"index.add_items(update_data, update_ids)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "48fe062a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.42857142857142855"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"expected_data = "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ec009685",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 2 additions & 2 deletions chromadb/test/property/test_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def _add_embeddings(self, embeddings: strategies.EmbeddingSet):
else:
documents = [None] * len(embeddings["ids"])

self.embeddings["metadatas"] += metadatas # type: ignore
self.embeddings["documents"] += documents # type: ignore
self.embeddings["metadatas"].extend(metadatas) # type: ignore
self.embeddings["documents"].extend(documents) # type: ignore

def _remove_embeddings(self, indices_to_remove: Set[int]):

Expand Down

0 comments on commit 35f93c2

Please sign in to comment.