Skip to content

Commit

Permalink
Merge pull request #824 from PrefectHQ/rm-global-client
Browse files Browse the repository at this point in the history
defer chroma client making
  • Loading branch information
zzstoatzz authored Feb 17, 2024
2 parents 31b42ad + 63efa1d commit 9c83004
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/marvin/tools/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def __call__(self, input: Documents) -> Embeddings:
return [create_openai_embeddings(input)]


client = HttpClient(host=HOST, port=PORT)
def get_http_client() -> HttpClient:
"""Get a Chroma HTTP client."""
return HttpClient(host=HOST, port=PORT)


async def query_chroma(
Expand All @@ -80,7 +82,7 @@ async def query_chroma(
User: "What are prefect blocks?"
Assistant: >>> query_chroma("What are prefect blocks?")
"""
collection_object = client.get_or_create_collection(
collection_object = get_http_client().get_or_create_collection(
name=collection or DEFAULT_COLLECTION_NAME,
embedding_function=OpenAIEmbeddingFunction(),
)
Expand Down Expand Up @@ -142,7 +144,7 @@ def store_document(
Returns:
The stored document.
"""
collection = client.get_or_create_collection(
collection = get_http_client().get_or_create_collection(
name=collection_name, embedding_function=OpenAIEmbeddingFunction()
)
doc_id = metadata.get("msg_id", str(uuid.uuid4()))
Expand Down

0 comments on commit 9c83004

Please sign in to comment.