Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server error due to Chroma query index dimensionality mismatch #296

Open
cowile opened this issue May 31, 2023 · 3 comments
Open

Server error due to Chroma query index dimensionality mismatch #296

cowile opened this issue May 31, 2023 · 3 comments

Comments

@cowile
Copy link

cowile commented May 31, 2023

I've been trying to set up an example Chroma database that can be queried with the retrieval plugin.

I generate the database with this code:

import chromadb
from chromadb.config import Settings
import os

cl = chromadb.Client(Settings(
    chroma_db_impl="duckdb+parquet",
    persist_directory=os.path.expanduser("~/Code/chatgpt-retrieval-plugin/openai")
))
co = cl.create_collection('openaiembeddings')

for c in range(ord('A'), ord('Z')+1):
    co.add(documents=chr(c), ids=chr(c))

Then I run the retrieval plugin with poetry run dev and try the plugin with ChatGPT.

Screenshot 2023-05-31 at 13-02-51 ChatGPT

After the ChatGPT session, the log says:

INFO:     Will watch for changes in these directories: ['/home/cwl/Code/chatgpt-retrieval-plugin']
INFO:     Uvicorn running on http://localhost:3333 (Press CTRL+C to quit)
INFO:     Started reloader process [103737] using WatchFiles
INFO:     Started server process [103748]
INFO:     Waiting for application startup.
Using embedded DuckDB with persistence: data will be stored in: openai
No embedding_function provided, using default embedding function: SentenceTransformerEmbeddingFunction
INFO:     Application startup complete.
Error: Dimensionality of (1536) does not match index dimensionality (384)
INFO:     127.0.0.1:57770 - "POST /query HTTP/1.1" 500 Internal Server Error
@atroyn
Copy link
Contributor

atroyn commented May 31, 2023

The issue is that when you added the documents, you used the built-in default embedding function.
If you want to use Chroma in this way, you should use the OpenAI embedding function when adding documents.

I'll add that to the chroma specific README.

@cowile
Copy link
Author

cowile commented Jun 5, 2023

Then the codebase should use the OpenAI embedding function in chroma_datastore.py. Currently that also uses the default when creating a chroma client.

@atroyn
Copy link
Contributor

atroyn commented Jun 5, 2023

For the retrieval plugin, the embeddings are handled above the data store interface. Embeddings for upsert are handled here: https://github.com/openai/chatgpt-retrieval-plugin/blob/742fdf7cfcd1ca6082de1ee2ee5dc5e14dc00e0f/datastore/datastore.py#LL18C15-L18C21

and for query, here:

query_embeddings = get_embeddings(query_texts)

Because you populated your index directly, we did not know that the OpenAI embedding function should be used, so used our default.

In chroma_datastore.py the function is deliberately set to None as it should never be called directly for collections created via the retrieval plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants