diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index b31314d..2b8e252 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -21,4 +21,4 @@ jobs: pip install pylint - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + pylint --ignored-modules=chromadb $(git ls-files '*.py') diff --git a/gnosis/chroma_client.py b/gnosis/chroma_client.py index 1186e08..88683ea 100644 --- a/gnosis/chroma_client.py +++ b/gnosis/chroma_client.py @@ -1,7 +1,6 @@ """A client for ChromaDB.""" import chromadb - -# from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction +from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction import streamlit as st @@ -12,12 +11,18 @@ def __init__(self, api_key, path="tmp/chroma"): """Initialize the client.""" self.client = chromadb.PersistentClient(path=path) self.api_key = api_key + self.embedding_function = OpenAIEmbeddingFunction( + api_key=self.api_key, model_name="text-embedding-3-small" + ) self.client.heartbeat() def get_collection(self, name): """Get a Chroma collection.""" try: - collection = self.client.get_collection(name=name) + collection = self.client.get_collection( + name=name, + embedding_function=self.embedding_function + ) return collection except AttributeError: return st.error("An error ocurred while getting the collection.") @@ -25,11 +30,9 @@ def get_collection(self, name): def create_collection(self, name): """Create a Chroma collection.""" try: - # embedding_function = OpenAIEmbeddingFunction( - # api_key=self.api_key, model_name="text-embedding-ada-002" - # ) collection = self.client.get_or_create_collection( - name=name # , embedding_function=embedding_function + name=name, + embedding_function=self.embedding_function ) return collection except AttributeError: diff --git a/gnosis/persistence.py b/gnosis/persistence.py index 81e779e..dea1f19 100644 --- a/gnosis/persistence.py +++ b/gnosis/persistence.py @@ -1,6 +1,7 @@ -# Use this module to pull persisted ChromaDB from Hugging Face Dataset on startup. +"""Persistence utilities for Gnosis.""" import os from huggingface_hub import snapshot_download +from huggingface_hub.errors import HfHubHTTPError, RepositoryNotFoundError REPO_ID = os.getenv("HF_DATASET_REPO") LOCAL_PATH = "tmp/chroma" @@ -16,5 +17,5 @@ def pull(): local_dir=LOCAL_PATH, token=os.getenv("HF_DATASET_TOKEN"), ) - except Exception: + except (HfHubHTTPError, RepositoryNotFoundError): os.makedirs(LOCAL_PATH, exist_ok=True) diff --git a/gnosis/search.py b/gnosis/search.py index eab4109..5eb10b0 100644 --- a/gnosis/search.py +++ b/gnosis/search.py @@ -11,7 +11,7 @@ def __init__(self, chroma_db): def run(self, query: str): """Run the Agent""" collection = self.chroma_db.get_collection("pdf-explainer") - results = collection.query(query_texts=[query], n_results=3)["documents"][0] + results = collection.query(query_texts=[query], n_results=5)["documents"][0] return "\n\n---\n\n".join(results) def collection_name(self): diff --git a/requirements.txt b/requirements.txt index 457daaa..3519e4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ cachetools==5.5.2 certifi==2025.4.26 charset-normalizer==3.4.2 chroma-hnswlib==0.7.6 -chromadb==0.5.7 +chromadb==1.5.9 click==8.4.1 comm==0.2.3 contourpy==1.3.3 @@ -110,6 +110,7 @@ psutil==7.1.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyarrow==20.0.0 +pybase64==1.4.3 pydantic==2.13.4 pydantic-settings==2.14.1 pydantic_core==2.46.4 diff --git a/wk_flow_requirements.txt b/wk_flow_requirements.txt index 6ed98fe..3519e4b 100644 --- a/wk_flow_requirements.txt +++ b/wk_flow_requirements.txt @@ -11,13 +11,14 @@ asttokens==3.0.0 attrs==25.3.0 backoff==2.2.1 bcrypt==5.0.0 +beautifulsoup4==4.15.0 blinker==1.9.0 build==1.5.0 cachetools==5.5.2 certifi==2025.4.26 charset-normalizer==3.4.2 chroma-hnswlib==0.7.6 -chromadb==0.5.7 +chromadb==1.5.9 click==8.4.1 comm==0.2.3 contourpy==1.3.3 @@ -50,6 +51,7 @@ importlib_resources==7.1.0 ipykernel==6.30.1 ipython==9.5.0 ipython_pygments_lexers==1.1.1 +itsdangerous==2.2.0 jedi==0.19.2 Jinja2==3.1.6 jiter==0.15.0 @@ -79,7 +81,6 @@ mypy_extensions==1.1.0 narwhals==1.40.0 nest-asyncio==1.6.0 numpy==1.26.4 -streamlit==1.58.0 oauthlib==3.3.1 onnxruntime==1.26.0 openai==1.55.3 @@ -109,6 +110,7 @@ psutil==7.1.0 ptyprocess==0.7.0 pure_eval==0.2.3 pyarrow==20.0.0 +pybase64==1.4.3 pydantic==2.13.4 pydantic-settings==2.14.1 pydantic_core==2.46.4 @@ -121,6 +123,7 @@ PyPika==0.51.1 pyproject_hooks==1.2.0 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 +python-multipart==0.0.32 pytz==2025.2 PyYAML==6.0.3 pyzmq==27.1.0 @@ -135,9 +138,11 @@ shellingham==1.5.4 six==1.17.0 smmap==5.0.2 sniffio==1.3.1 +soupsieve==2.8.4 SQLAlchemy==2.0.50 stack-data==0.6.3 starlette==1.3.1 +streamlit==1.58.0 tenacity==8.5.0 tiktoken==0.7.0 tokenizers==0.23.1 @@ -157,5 +162,6 @@ watchfiles==1.2.0 wcwidth==0.2.13 websocket-client==1.9.0 websockets==16.0 +wikipedia==1.4.0 wrapt==2.2.1 yarl==1.24.2