introducing pinecone stuff

This commit is contained in:
Thomas Lemoine
2023-03-24 17:01:18 -04:00
parent 2415220068
commit 3cd271d8d7
2 changed files with 154 additions and 2 deletions
+2 -1
View File
@@ -3,4 +3,5 @@ openai
numpy
langchain
requests
tiktoken
tiktoken
pinecone
+152 -1
View File
@@ -1305,6 +1305,157 @@
"limited_text = limit_tokens(input_text, 1000)\n",
"print(limited_text)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import pinecone\n",
"import config\n",
"PINECONE_API_KEY = config.PINECONE_API_KEY\n",
"\n",
"pinecone.init(api_key=PINECONE_API_KEY, environment=\"us-central1-gcp\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['quickstart']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"pinecone.create_index(\"quickstart\", dimension=8, metric=\"euclidean\", pod_type=\"p1\")\n",
"pinecone.list_indexes()\n",
"# Returns:\n",
"# ['quickstart']"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"index = pinecone.Index(\"quickstart\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'upserted_count': 5}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Upsert sample data (5 8-dimensional vectors)\n",
"index.upsert([\n",
" (\"A\", [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]),\n",
" (\"B\", [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2]),\n",
" (\"C\", [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]),\n",
" (\"D\", [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4]),\n",
" (\"E\", [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5])\n",
"])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'dimension': 8,\n",
" 'index_fullness': 0.0,\n",
" 'namespaces': {'': {'vector_count': 5}},\n",
" 'total_vector_count': 5}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"index.describe_index_stats()\n",
"# Returns:\n",
"# {'dimension': 8, 'index_fullness': 0.0, 'namespaces': {'': {'vector_count': 5}}}"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'matches': [{'id': 'C',\n",
" 'score': 0.0,\n",
" 'values': [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]},\n",
" {'id': 'D',\n",
" 'score': 0.0799999237,\n",
" 'values': [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4]},\n",
" {'id': 'B',\n",
" 'score': 0.0800000429,\n",
" 'values': [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2]}],\n",
" 'namespace': ''}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"index.query(\n",
" vector=[0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3],\n",
" top_k=3,\n",
" include_values=True\n",
")\n",
"# Returns:\n",
"# {'matches': [{'id': 'C',\n",
"# 'score': 0.0,\n",
"# 'values': [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]},\n",
"# {'id': 'D',\n",
"# 'score': 0.0799999237,\n",
"# 'values': [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4]},\n",
"# {'id': 'B',\n",
"# 'score': 0.0800000429,\n",
"# 'values': [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2]}],\n",
"# 'namespace': ''}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pinecone.delete_index(\"quickstart\")"
]
}
],
"metadata": {
@@ -1323,7 +1474,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.7"
},
"orig_nbformat": 4,
"vscode": {