Skip to content

Commit bb7d261

Browse files
committed
refactor: parameterize PINECONE_METRIC and PINECONE_DIMENSIONS. strongly type all properties
1 parent 5f85921 commit bb7d261

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ SHELL := /bin/bash
33
ifneq ("$(wildcard .env)","")
44
include .env
55
else
6-
$(shell echo -e "OPENAI_API_ORGANIZATION=PLEASE-ADD-ME\nOPENAI_API_KEY=PLEASE-ADD-ME\nPINECONE_API_KEY=PLEASE-ADD-ME\nPINECONE_ENVIRONMENT=gcp-starter\nPINECONE_INDEX_NAME=hsr\nPINECONE_VECTORSTORE_TEXT_KEY=lc_id\nOPENAI_CHAT_MODEL_NAME=gpt-3.5-turbo\nOPENAI_PROMPT_MODEL_NAME=text-davinci-003\nOPENAI_CHAT_TEMPERATURE=0.0\nOPENAI_CHAT_MAX_RETRIES=3\nDEBUG_MODE=True\n" >> .env)
6+
$(shell echo -e "OPENAI_API_ORGANIZATION=PLEASE-ADD-ME\n\
7+
OPENAI_API_KEY=PLEASE-ADD-ME\n\
8+
PINECONE_API_KEY=PLEASE-ADD-ME\n\
9+
PINECONE_ENVIRONMENT=gcp-starter\n\
10+
PINECONE_INDEX_NAME=hsr\n\
11+
PINECONE_VECTORSTORE_TEXT_KEY=lc_id\n\
12+
PINECONE_METRIC=dotproduct\n\
13+
PINECONE_DIMENSIONS=1536\n\
14+
OPENAI_CHAT_MODEL_NAME=gpt-3.5-turbo\n\
15+
OPENAI_PROMPT_MODEL_NAME=text-davinci-003\n\
16+
OPENAI_CHAT_TEMPERATURE=0.0\n\
17+
OPENAI_CHAT_MAX_RETRIES=3\n\
18+
DEBUG_MODE=True\n" >> .env)
719
endif
820

921
.PHONY: analyze init activate test lint clean

models/const.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
PINECONE_ENVIRONMENT = os.environ["PINECONE_ENVIRONMENT"]
1818
PINECONE_INDEX_NAME = os.environ.get("PINECONE_INDEX_NAME", "hsr")
1919
PINECONE_VECTORSTORE_TEXT_KEY = os.environ.get("PINECONE_VECTORSTORE_TEXT_KEY", "lc_id")
20+
PINECONE_METRIC = os.environ.get("PINECONE_METRIC", "dotproduct")
21+
PINECONE_DIMENSIONS = int(os.environ.get("PINECONE_DIMENSIONS", 1536))
2022
OPENAI_CHAT_MODEL_NAME = os.environ.get("OPENAI_CHAT_MODEL_NAME", "gpt-3.5-turbo")
2123
OPENAI_PROMPT_MODEL_NAME = os.environ.get("OPENAI_PROMPT_MODEL_NAME", "text-davinci-003")
2224
OPENAI_CHAT_TEMPERATURE = float(os.environ.get("OPENAI_CHAT_TEMPERATURE", 0.0))
@@ -48,6 +50,8 @@ class Config(metaclass=ReadOnly):
4850
PINECONE_ENVIRONMENT = PINECONE_ENVIRONMENT
4951
PINECONE_INDEX_NAME = PINECONE_INDEX_NAME
5052
PINECONE_VECTORSTORE_TEXT_KEY: str = PINECONE_VECTORSTORE_TEXT_KEY
53+
PINECONE_METRIC: str = PINECONE_METRIC
54+
PINECONE_DIMENSIONS: int = PINECONE_DIMENSIONS
5155

5256

5357
class Credentials(metaclass=ReadOnly):

models/hybrid_search_retreiver.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self):
8989

9090
# prompting wrapper
9191
@property
92-
def chat(self):
92+
def chat(self) -> ChatOpenAI:
9393
"""ChatOpenAI lazy read-only property."""
9494
if self._chat is None:
9595
self._chat = ChatOpenAI(
@@ -104,7 +104,7 @@ def chat(self):
104104

105105
# embeddings
106106
@property
107-
def openai_embeddings(self):
107+
def openai_embeddings(self) -> OpenAIEmbeddings:
108108
"""OpenAIEmbeddings lazy read-only property."""
109109
if self._openai_embeddings is None:
110110
self._openai_embeddings = OpenAIEmbeddings(
@@ -113,14 +113,14 @@ def openai_embeddings(self):
113113
return self._openai_embeddings
114114

115115
@property
116-
def pinecone_index(self):
116+
def pinecone_index(self) -> pinecone.Index:
117117
"""pinecone.Index lazy read-only property."""
118118
if self._pinecone_index is None:
119119
self._pinecone_index = pinecone.Index(index_name=Config.PINECONE_INDEX_NAME)
120120
return self._pinecone_index
121121

122122
@property
123-
def vector_store(self):
123+
def vector_store(self) -> Pinecone:
124124
"""Pinecone lazy read-only property."""
125125
if self._vector_store is None:
126126
self._vector_store = Pinecone(
@@ -131,14 +131,14 @@ def vector_store(self):
131131
return self._vector_store
132132

133133
@property
134-
def text_splitter(self):
134+
def text_splitter(self) -> TextSplitter:
135135
"""TextSplitter lazy read-only property."""
136136
if self._text_splitter is None:
137137
self._text_splitter = TextSplitter()
138138
return self._text_splitter
139139

140140
@property
141-
def bm25_encoder(self):
141+
def bm25_encoder(self) -> BM25Encoder:
142142
"""BM25Encoder lazy read-only property."""
143143
if self._b25_encoder is None:
144144
self._b25_encoder = BM25Encoder().default()
@@ -193,7 +193,10 @@ def load(self, filepath: str):
193193
}
194194
logging.debug("Creating index. This may take a few minutes...")
195195
pinecone.create_index(
196-
Config.PINECONE_INDEX_NAME, dimension=1536, metric="dotproduct", metadata_config=metadata_config
196+
Config.PINECONE_INDEX_NAME,
197+
dimension=Config.PINECONE_DIMENSIONS,
198+
metric=Config.PINECONE_METRIC,
199+
metadata_config=metadata_config,
197200
)
198201

199202
pdf_files = glob.glob(os.path.join(filepath, "*.pdf"))

0 commit comments

Comments
 (0)