Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
17 changes: 10 additions & 7 deletions gnosis/chroma_client.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -12,24 +11,28 @@ 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.")

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:
Expand Down
5 changes: 3 additions & 2 deletions gnosis/persistence.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
2 changes: 1 addition & 1 deletion gnosis/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions wk_flow_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Loading