Skip to content

Instantly share code, notes, and snippets.

@mdouze
Created May 23, 2020 09:52
Show Gist options
  • Save mdouze/fa6a2951fecb6d965a2aa66d20474a93 to your computer and use it in GitHub Desktop.
Save mdouze/fa6a2951fecb6d965a2aa66d20474a93 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import faiss"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"index = faiss.IndexIDMap2(faiss.IndexFlatL2(32))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"ids = np.random.randint(0, 5000, size=10)\n",
"x = np.random.rand(10, 32).astype('float32')\n",
"index.add_with_ids(x, ids)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4859, 1690, 211, 949, 2776, 3864, 1524, 4719, 3805, 2736])"
]
},
"execution_count": 10,
"metadata": {
"bento_obj_id": "140351030092064"
},
"output_type": "execute_result"
}
],
"source": [
"faiss.vector_to_array(index.id_map)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4859, 1690, 211, 949, 2776, 3864, 1524, 4719, 3805, 2736])"
]
},
"execution_count": 11,
"metadata": {
"bento_obj_id": "140351031290096"
},
"output_type": "execute_result"
}
],
"source": [
"ids"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"bento_stylesheets": {
"bento/extensions/flow/main.css": true,
"bento/extensions/kernel_selector/main.css": true,
"bento/extensions/kernel_ui/main.css": true,
"bento/extensions/new_kernel/main.css": true,
"bento/extensions/system_usage/main.css": true,
"bento/extensions/theme/main.css": true
},
"kernelspec": {
"display_name": "faiss",
"language": "python",
"name": "bento_kernel_faiss"
},
"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.7.5+"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment