Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload 3 files
Browse files- rag_chain/chain.py +3 -4
- rag_chain/retrievers_setup.py +5 -2
rag_chain/chain.py
CHANGED
@@ -128,7 +128,6 @@ def get_rag_chain(model_name: str = "gpt-4", temperature: float = 0.2) -> tuple[
|
|
128 |
)
|
129 |
|
130 |
# Compression retriever for practitioners db
|
131 |
-
# TODO
|
132 |
practitioners_db_compression_retriever = compression_retriever_setup(
|
133 |
practitioners_ensemble_retriever,
|
134 |
embeddings_model="text-embedding-ada-002",
|
@@ -139,18 +138,18 @@ def get_rag_chain(model_name: str = "gpt-4", temperature: float = 0.2) -> tuple[
|
|
139 |
dense_retriever_client = DenseRetrieverClient(embeddings_model=embeddings_model,
|
140 |
collection_name="tall_tree_db")
|
141 |
tall_tree_db_dense_retriever = dense_retriever_client.get_dense_retriever(search_type="similarity",
|
142 |
-
k=
|
143 |
# Compression retriever for tall_tree_db
|
144 |
tall_tree_db_compression_retriever = compression_retriever_setup(
|
145 |
tall_tree_db_dense_retriever,
|
146 |
embeddings_model="text-embedding-ada-002",
|
147 |
-
similarity_threshold=0.
|
148 |
)
|
149 |
|
150 |
# Set conversation history window memory. It only uses the last k interactions.
|
151 |
memory = ConversationBufferWindowMemory(memory_key="history",
|
152 |
return_messages=True,
|
153 |
-
k=
|
154 |
|
155 |
# Set up runnable using LCEL
|
156 |
setup_and_retrieval = {"practitioners_db": itemgetter("message")
|
|
|
128 |
)
|
129 |
|
130 |
# Compression retriever for practitioners db
|
|
|
131 |
practitioners_db_compression_retriever = compression_retriever_setup(
|
132 |
practitioners_ensemble_retriever,
|
133 |
embeddings_model="text-embedding-ada-002",
|
|
|
138 |
dense_retriever_client = DenseRetrieverClient(embeddings_model=embeddings_model,
|
139 |
collection_name="tall_tree_db")
|
140 |
tall_tree_db_dense_retriever = dense_retriever_client.get_dense_retriever(search_type="similarity",
|
141 |
+
k=8)
|
142 |
# Compression retriever for tall_tree_db
|
143 |
tall_tree_db_compression_retriever = compression_retriever_setup(
|
144 |
tall_tree_db_dense_retriever,
|
145 |
embeddings_model="text-embedding-ada-002",
|
146 |
+
similarity_threshold=0.74
|
147 |
)
|
148 |
|
149 |
# Set conversation history window memory. It only uses the last k interactions.
|
150 |
memory = ConversationBufferWindowMemory(memory_key="history",
|
151 |
return_messages=True,
|
152 |
+
k=6)
|
153 |
|
154 |
# Set up runnable using LCEL
|
155 |
setup_and_retrieval = {"practitioners_db": itemgetter("message")
|
rag_chain/retrievers_setup.py
CHANGED
@@ -47,12 +47,14 @@ class DenseRetrieverClient:
|
|
47 |
@cache
|
48 |
def load_qdrant_collection(self):
|
49 |
"""Load Qdrant collection for a given embeddings model."""
|
50 |
-
|
|
|
|
|
51 |
self.qdrant_collection = self.set_qdrant_collection(
|
52 |
OpenAIEmbeddings(model=self.embeddings_model))
|
53 |
else:
|
54 |
raise ValueError(
|
55 |
-
f"Invalid embeddings model: {self.embeddings_model}.
|
56 |
|
57 |
return self.qdrant_collection
|
58 |
|
@@ -156,6 +158,7 @@ def compression_retriever_setup(base_retriever, embeddings_model: str = "text-em
|
|
156 |
base_retriever: Retriever to be filtered.
|
157 |
similarity_threshold (float, optional): The similarity threshold for the EmbeddingsFilter.
|
158 |
Documents with a similarity score below this threshold will be filtered out. Defaults to 0.76 (Obtained by experimenting with text-embeddings-ada-002).
|
|
|
159 |
|
160 |
Returns:
|
161 |
ContextualCompressionRetriever: The created ContextualCompressionRetriever.
|
|
|
47 |
@cache
|
48 |
def load_qdrant_collection(self):
|
49 |
"""Load Qdrant collection for a given embeddings model."""
|
50 |
+
# TODO: Test new OpenAI text embeddings models
|
51 |
+
openai_text_embeddings = ["text-embedding-ada-002"]
|
52 |
+
if self.embeddings_model in openai_text_embeddings:
|
53 |
self.qdrant_collection = self.set_qdrant_collection(
|
54 |
OpenAIEmbeddings(model=self.embeddings_model))
|
55 |
else:
|
56 |
raise ValueError(
|
57 |
+
f"Invalid embeddings model: {self.embeddings_model}. Valid options are {', '.join(openai_text_embeddings)}.")
|
58 |
|
59 |
return self.qdrant_collection
|
60 |
|
|
|
158 |
base_retriever: Retriever to be filtered.
|
159 |
similarity_threshold (float, optional): The similarity threshold for the EmbeddingsFilter.
|
160 |
Documents with a similarity score below this threshold will be filtered out. Defaults to 0.76 (Obtained by experimenting with text-embeddings-ada-002).
|
161 |
+
** Be careful with this parameter, as it can have a big impact on the results and highly depends on the embeddings model used.
|
162 |
|
163 |
Returns:
|
164 |
ContextualCompressionRetriever: The created ContextualCompressionRetriever.
|