Spaces:
Runtime error
Runtime error
J.P. Pérez Tejada commited on
Commit ·
ab32b96
1
Parent(s): 31027f9
Change default embeddings to openai embeddings
Browse files- gnosis/chroma_client.py +10 -7
- gnosis/search.py +1 -1
gnosis/chroma_client.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
"""A client for ChromaDB."""
|
| 2 |
import chromadb
|
| 3 |
-
|
| 4 |
-
# from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction
|
| 5 |
import streamlit as st
|
| 6 |
|
| 7 |
|
|
@@ -12,12 +11,18 @@ class ChromaDB:
|
|
| 12 |
"""Initialize the client."""
|
| 13 |
self.client = chromadb.PersistentClient(path=path)
|
| 14 |
self.api_key = api_key
|
|
|
|
|
|
|
|
|
|
| 15 |
self.client.heartbeat()
|
| 16 |
|
| 17 |
def get_collection(self, name):
|
| 18 |
"""Get a Chroma collection."""
|
| 19 |
try:
|
| 20 |
-
collection = self.client.get_collection(
|
|
|
|
|
|
|
|
|
|
| 21 |
return collection
|
| 22 |
except AttributeError:
|
| 23 |
return st.error("An error ocurred while getting the collection.")
|
|
@@ -25,11 +30,9 @@ class ChromaDB:
|
|
| 25 |
def create_collection(self, name):
|
| 26 |
"""Create a Chroma collection."""
|
| 27 |
try:
|
| 28 |
-
# embedding_function = OpenAIEmbeddingFunction(
|
| 29 |
-
# api_key=self.api_key, model_name="text-embedding-ada-002"
|
| 30 |
-
# )
|
| 31 |
collection = self.client.get_or_create_collection(
|
| 32 |
-
name=name
|
|
|
|
| 33 |
)
|
| 34 |
return collection
|
| 35 |
except AttributeError:
|
|
|
|
| 1 |
"""A client for ChromaDB."""
|
| 2 |
import chromadb
|
| 3 |
+
from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction
|
|
|
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
|
|
|
|
| 11 |
"""Initialize the client."""
|
| 12 |
self.client = chromadb.PersistentClient(path=path)
|
| 13 |
self.api_key = api_key
|
| 14 |
+
self.embedding_function = OpenAIEmbeddingFunction(
|
| 15 |
+
api_key=self.api_key, model_name="text-embedding-3-small"
|
| 16 |
+
)
|
| 17 |
self.client.heartbeat()
|
| 18 |
|
| 19 |
def get_collection(self, name):
|
| 20 |
"""Get a Chroma collection."""
|
| 21 |
try:
|
| 22 |
+
collection = self.client.get_collection(
|
| 23 |
+
name=name,
|
| 24 |
+
embedding_function=self.embedding_function
|
| 25 |
+
)
|
| 26 |
return collection
|
| 27 |
except AttributeError:
|
| 28 |
return st.error("An error ocurred while getting the collection.")
|
|
|
|
| 30 |
def create_collection(self, name):
|
| 31 |
"""Create a Chroma collection."""
|
| 32 |
try:
|
|
|
|
|
|
|
|
|
|
| 33 |
collection = self.client.get_or_create_collection(
|
| 34 |
+
name=name,
|
| 35 |
+
embedding_function=self.embedding_function
|
| 36 |
)
|
| 37 |
return collection
|
| 38 |
except AttributeError:
|
gnosis/search.py
CHANGED
|
@@ -11,7 +11,7 @@ class Search:
|
|
| 11 |
def run(self, query: str):
|
| 12 |
"""Run the Agent"""
|
| 13 |
collection = self.chroma_db.get_collection("pdf-explainer")
|
| 14 |
-
results = collection.query(query_texts=[query], n_results=
|
| 15 |
return "\n\n---\n\n".join(results)
|
| 16 |
|
| 17 |
def collection_name(self):
|
|
|
|
| 11 |
def run(self, query: str):
|
| 12 |
"""Run the Agent"""
|
| 13 |
collection = self.chroma_db.get_collection("pdf-explainer")
|
| 14 |
+
results = collection.query(query_texts=[query], n_results=5)["documents"][0]
|
| 15 |
return "\n\n---\n\n".join(results)
|
| 16 |
|
| 17 |
def collection_name(self):
|