2

I am trying to use chroma vector store in Python but I cannot make it work.

When I tried to create a persistent client using the command below I got the below error.

client = chromadb.PersistentClient(path=path="/path/to/save/to")

ERROR: RuntimeError: Chroma is running in http-only client mode, and can only be run with 'chromadb.api.fastapi.FastAPI' as the chroma_api_impl. see https://docs.trychroma.com/usage-guide?lang=py#using-the-python-http-only-client for more information.

I also tried to run chroma in http-only client mode. I used the code below:

from chromadb import HttpClient

from chromadb.config import Settings

settings = Settings(chroma_api_impl="chromadb.api.fastapi.FastAPI", allow_reset=True, anonymized_telemetry=False)

client = HttpClient(host='localhost',port=8000,settings=settings)

it worked but when I tried to create a collection I got the following error:

ERROR: ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Any help would be truly appreciated :).

Many many thanks

3 Answers 3

2

To create a local non-persistent (data gone after execution finished) Chroma database, you can do

# embedding model as example
embedding_function = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")

# load it into Chroma
db = Chroma.from_documents(docs, embedding_function)

If you want to create/ load from a local persistent Chroma vectorstore,

# save to disk
db2 = Chroma.from_documents(docs, embedding_function,
                            persist_directory="./chroma_db")
docs = db2.similarity_search(query)

# load from disk
db3 = Chroma(persist_directory="./chroma_db", embedding_function=embedding_function)
docs = db3.similarity_search(query)
print(docs[0].page_content)

If you want to pass a Chroma client into LangChain, you would have to have a standalone Chroma vectorstore engine running over HTTP.

Here's the reference doc > https://python.langchain.com/docs/integrations/vectorstores/chroma

Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks! But when I tried your suggestion I got the below error: ERROR: RuntimeError: Chroma is running in http-only client mode, and can only be run with 'chromadb.api.fastapi.FastAPI' as the chroma_api_impl. see docs.trychroma.com/… for more information. Any other suggestions?
this answer works locally but I think OP wanted to get it running over http. I also arrived at this QA for that reason. Anyway, the reference doc link is helpful, but you may want to quote the relevant parts from the docs into your answer as link rot is very likely for these fast evolving libraries.
1

I came here for the same reason. You can solve it with (basically)

model_kwargs=[dict]trust_remote_code=True

Comments

0

Rewrite the simple code and please give a try

from langchain.vectorstores import Chroma
from langchain.embeddings import HuggingFaceEmbeddings

# using open source llm and download to local disk
embedding_function = HuggingFaceEmbeddings(
    model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")

# use `from_texts` instead of `from_documents`, for reference
vectorstore = Chroma.from_texts(["harry potter's owl is in the castle."], 
                        embedding_function, persist_directory="./chroma_db")
query = "where is Harry Potter's Hedwig?"
docs = vectorstore.similarity_search(query)
print(docs[0].page_content)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.