Skip to content
Open
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
44 changes: 12 additions & 32 deletions src/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ en_core_web_sm = {url = "https://github.com/explosion/spacy-models/releases/down
# requires running the Chroma server with trust_remote_code=true, which Sherpa
# does not do. Bump once an upstream fixed release ships.
chromadb = "^1.0.9"
langchain-chroma = "^0.2.5"
boto3 = "^1.28.77"
beautifulsoup4 = "4.15.0"

Expand Down
34 changes: 11 additions & 23 deletions src/sherpa_ai/connectors/scripts/query_chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import json
import uuid

import chromadb
from chromadb.config import Settings
from dotenv import load_dotenv
from langchain_openai import OpenAIEmbeddings
import chromadb
from chromadb.config import Settings
from chromadb.utils import embedding_functions
from dotenv import load_dotenv
from loguru import logger


Expand All @@ -16,29 +16,17 @@ def main(args):
settings=Settings(allow_reset=True),
)

embedding_func = OpenAIEmbeddings()
try:
from langchain_chroma import Chroma
except ImportError:
raise ImportError(
"Could not import langchain_chroma python package. "
"This is needed in order to use Chroma. "
"Please install it with `pip install langchain-chroma`"
)
chroma = Chroma(
client=client,
collection_name=args.chroma_index,
embedding_function=embedding_func,
embedding_func = embedding_functions.OpenAIEmbeddingFunction(
model_name="text-embedding-ada-002"
)
collection = client.get_or_create_collection(
name=args.chroma_index, embedding_function=embedding_func
)

query = input("Enter query: ")
results = chroma.similarity_search(
query=query,
number_of_results=5,
k=1
)
results = collection.query(query_texts=[query], n_results=1)

logger.info(results[0].page_content)
logger.info(results["documents"][0][0])

logger.info("Done! Chroma is up and running.")

Expand Down
Loading