File size: 3,063 Bytes
040f332
 
 
 
566d4e4
040f332
566d4e4
040f332
566d4e4
 
 
 
 
 
 
040f332
566d4e4
 
 
 
040f332
566d4e4
040f332
566d4e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
040f332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from langchain.vectorstores import Chroma, Pinecone\n",
    "from langchain.embeddings.openai import OpenAIEmbeddings\n",
    "import pinecone \n",
    "import os\n",
    "from dotenv import load_dotenv, find_dotenv\n",
    "load_dotenv(find_dotenv()                              )\n",
    "\n",
    "pinecone.init(\n",
    "    api_key=os.environ[\"PINECONE_API_KEY\"], \n",
    "    environment=os.environ[\"PINECONE_ENV\"]\n",
    ")\n",
    "\n",
    "OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')\n",
    "\n",
    "PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')\n",
    "PINECONE_API_ENV = os.environ.get('PINECONE_API_ENV') # You may need to switch with your env\n",
    "PINECONE_INDEX_NAME= os.environ.get('PINECONE_INDEX_NAME')\n",
    "\n",
    "def get_default_index() -> Pinecone:\n",
    "    embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)\n",
    "    # initialize pinecone\n",
    "    pinecone.init(\n",
    "        api_key=PINECONE_API_KEY,  # find at app.pinecone.io\n",
    "        environment=PINECONE_API_ENV  # next to api key in console\n",
    "    )\n",
    "    index_name = PINECONE_INDEX_NAME # put in the name of your pinecone index here\n",
    "    print(PINECONE_API_ENV)\n",
    "    print(PINECONE_API_KEY)\n",
    "    if index_name not in pinecone.list_indexes():\n",
    "        # we create a new index\n",
    "        pinecone.create_index(\n",
    "            name=index_name,\n",
    "            metric='cosine',\n",
    "            dimension=len(res[0])  # 1536 dim of text-embedding-ada-002\n",
    "        )\n",
    "    index = pinecone.GRPCIndex(index_name)\n",
    "    return index\n",
    "\n",
    "index = get_default_index()\n",
    "index.describe_index_stats()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from modules.vector_stores.vector_stores.pinecone_manager import get_default_pinecone_session, PineconeSessionManager\n",
    "import os\n",
    "from langchain.vectorstores import Pinecone\n",
    "PINECONE_INDEX_NAME= os.environ.get('PINECONE_INDEX_NAME')\n",
    "print(PINECONE_INDEX_NAME)\n",
    "### This is the default pinecone session manager\n",
    "pinecone_session: PineconeSessionManager = get_default_pinecone_session(PINECONE_INDEX_NAME)\n",
    "### This is the index for the default pinecone session manager\n",
    "vector_index: Pinecone = pinecone_session.docsearch"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}