-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_and_configure_pinecone_index.py
executable file
·79 lines (69 loc) · 3.76 KB
/
create_and_configure_pinecone_index.py
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
#!/usr/bin/env python
################################################################################
# commbase-genai-slm-ollama-phi3-mini-memory-remote-rag-pinecone #
# #
# A sophisticated AI assistant's Small Language Model (Phi3), enhanced by #
# Retrieval-Augmented Generation (RAG) for improved response accuracy, and #
# supported by a Pinecone semantic vector database. #
# #
# Change History #
# 06/25/2024 Esteban Herrera Original code. #
# Add new history entries as needed. #
# #
# #
################################################################################
################################################################################
################################################################################
# #
# Copyright (c) 2022-present Esteban Herrera C. #
# stv.herrera@gmail.com #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# create_and_configure_pinecone_index.py
# Creates and configures a new Pinecone index named 'new-pinecone-index'
# Imports
import functions
import time
from pinecone import Pinecone, ServerlessSpec
# Call test_embedding_model()
model, xq = functions.test_embedding_model()
# Print the model details
print("Model: ", model)
# Print the dimensions of the embedding vector
print("Single query dimensions:", xq.shape)
# Initialize the Pinecone client with your API key
pc = Pinecone(api_key="")
# Define the cloud provider and region
cloud = 'aws'
region = 'us-east-1'
spec = ServerlessSpec(cloud=cloud, region=region)
index_name = 'commbase-log-chats'
# Check if index already exists (it shouldn't if this is first time)
if index_name not in pc.list_indexes().names():
# If does not exist, create index
pc.create_index(
index_name,
dimension=model.get_sentence_embedding_dimension(),
metric='cosine',
spec=spec
)
# Wait for index to be initialized
while not pc.describe_index(index_name).status['ready']:
time.sleep(1)
# Connect to index and print the index statistics
index = pc.Index(index_name)
print("")
print("Index statistics:")
print(index.describe_index_stats())