Notebooks
C
Chroma
Visualizations

Visualizations

AIembeddings-visualizerchroma-cookbooksChromaDBllm-evaluationai-agents

Visualizing Embedding Spaces

Embeddings are high-dimensional representations of our data. While they are useful for various AI applications, they can be hard to reason about. Projecting these high-dimensional objects onto a 2D space, allows us to visualize them, identify clusters, highlight anomalies, and more generally assess the quality of our data.

In this notebook, we will see how visualizing an embeddings space can help us reason about our data and identify pitfalls in a RAG pipeline. We will use a dataset of customer support messages from Chroma Cloud. One possible application of such dataset is building a customer support agent. Each user query can map to a good answer, and when a new query comes in, the agent can look up this dataset to compile its answer.

Setup

  1. Log in to your Chroma Cloud account. If you are a first time user, you can sign up to get your own account. You will get free credits that are more than enough to run this notebook.
  2. Create a new Database, and name it visualizations, or any name of your choice.
  3. Choose the "Load a sample dataset" option, and then the "Customer support messages" dataset. This will copy the dataset into a collection in your new Chroma Database.
  4. In the "Settings" tab, scroll down and choose the .env option. Click on the "Create API key" button, and copy the connection environment variables.
  5. Create a new .env file in this directory (chroma-cookbooks/embeddings-visualizer) and paste your environment variables.
  6. You will also need an OpenAI API key. Set it in your .env file under OPENAI_API_KEY.
  7. Load the keys in this notebook
[121]

Explore the Dataset

Let's get the dataset into this notebook. In our get call, we include the embeddings in this collection so we can use them for our visualizations later on.

[122]

We can see that the first few records contain customer questions about a product. Each record has the from_email metadata field indicating the user email of the inquirer.

Visualizing our Embedding Space

We will project our embeddings onto a 2-dimensional space using umap; it is similar to PCA in the sense that it is a dimensionality reduction technique, but umap tries to preserve the distances between points as much as possible from the original vector space, whereas PCA tries to find the dominant directions onto which the data is then projected.

Here, we fit a umap transformer to the embeddings associated with each customer support query. We set the random states so we can get reproducable results.

Note: You might get a warning about the random state being set. This is intentional so the results of this notebook remain consistent across runs

[123]
/Users/itaismith/Developer/chroma-cookbooks/embeddings-visualizer/venv/lib/python3.13/site-packages/umap/umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(

Now that we have a umap transformer, we can write a function that will project embeddings into a 2-dimensional space:

[124]

We will use matplotlib to visualize our projected embeddings in a scatterplot:

[125]
100%|████████████████████████████████████████| 300/300 [00:00<00:00, 618.05it/s]
(np.float64(-6.513811683654785),
, np.float64(17.91141757965088),
, np.float64(-6.976258444786072),
, np.float64(14.565848994255067))
Output

We can see that our records cluster nicely into clusters. This suggests that there are groups of records that cover similar topics or ideas. They are semantically similar, so they appear close together in the embedding space. We can already see that some clusters are larger than others. Suggesting that this dataset has good cover for some customer questions but not others.

Using Visualizations for Data Analysis

To start analyzing our dataset, we can submit some queries and visualize them on the same space. Let's query for questions about account deletion, and see what records we get back

[126]
I’m trying to downgrade from the Pro plan and completely cancel my subscription before the next renewal, but the Cancel button in the billing settings is greyed out. Could you walk me through the exact steps to terminate the account and confirm whether my stored projects will be deleted or just archived?

I need to cancel my Pro subscription before it renews next week, but the cancel button in my account settings is greyed out. If I delete my workspace, will that automatically stop the subscription, and will I still have read-only access to my notes afterward?

I’m trying to cancel my subscription before the next billing date, but I can’t find the option in the account settings. Is there a specific place to request cancellation and will I still have access to my projects until the end of the current cycle?

I’m trying to cancel my Team Plus subscription, but the billing page only shows options to upgrade or pause the plan. If I complete the cancellation, will my projects be deleted right away or will I keep access until the current cycle ends?

I’m trying to cancel my subscription before the renewal date but the option in Account Settings just keeps looping me back to the dashboard. Can you explain the exact steps to finalize the cancellation and confirm that I won’t be billed next cycle?

Plotting Queries

Let's visualize this query and the results in our embedding space. We will create a function that produces the plot of our embedding space, sets the query to be a red X, and the results of the query as empty green circles:

[127]
[128]
100%|█████████████████████████████████████████████| 1/1 [00:00<00:00, 95.55it/s]
100%|████████████████████████████████████████████| 5/5 [00:00<00:00, 218.20it/s]
Output

By the records and the visualization, we can see that one of our clusters is clearly about subscription cancellation. This also suggests that the retrieval for queries about cancellation are "tight". Our dataset has good cover for this topic.

We can also try a very general query like I need help with something:

[129]
I clicked “Forgot Password” and got the email, but the link opens a blank page instead of the reset form. I’m locked out of my account with a project deadline in a few hours—can you help me get a new password?

I requested a password reset yesterday, but the email link never showed up in my inbox or spam folder. Can you help me regain access to my workspace so I don’t lose the tasks and notes I have due today?

I’m on the free tier of your productivity suite and need to upgrade to the Team Pro plan, but I’m worried about how the change will affect my existing projects and shared workspaces. Can you walk me through the upgrade steps and confirm whether I can roll back or adjust seats later if our budget changes?

I clicked “Forgot Password” twice today, but the reset email never shows up in my inbox or spam folder. Can you help me get a new link so I can log back in and finish syncing my project boards?

I’m trying to switch from the free tier to the Pro plan so I can unlock the automation workflows, but I get a “payment method not supported” error every time I submit my card. Can you walk me through what I need to do to complete the upgrade without losing my existing projects and shared folders?

100%|████████████████████████████████████████████| 1/1 [00:00<00:00, 109.18it/s]
100%|████████████████████████████████████████████| 5/5 [00:00<00:00, 223.95it/s]
Output

We can see that the results are spread across the embedding space, and a simple retrieval pass for such query will not give an LLM enough information. In such cases, we often need to resort to more sophisticated methods like agentic search, asking for user clarification, etc.

Idenitfying Gaps

Visualizing the space is also helpful for identifying gaps in our data. For example, when we issue the query is your platform GDPR compliant:

[130]
I’m integrating your platform into our internal dashboard and the public API docs still reference v2 endpoints, but the sandbox only returns responses for v3. Could you clarify where I can find the updated schema and examples for creating recurring tasks via v3, and whether the OAuth scopes have changed?

I’m integrating our internal dashboard with your productivity platform, but the API documentation still references the deprecated v1 endpoints and glosses over how OAuth refresh tokens are handled. Can you provide updated guidance on token refresh flow and confirm whether the new v2 endpoints support the same rate limits?

I’m trying to connect your platform with our Jira instance, but the webhook keeps failing and I’m not seeing any detailed error logs. Can you walk me through the correct authentication steps and any required permissions so our existing projects will sync properly?

Your platform automatically renewed my Pro subscription yesterday even though I disabled auto-renew weeks ago. I'd like to request a full refund for the unexpected charge and to confirm that my projects will remain intact if I revert to the free plan.

I’m on the free Basic plan of your TaskHub platform and want to switch to the Pro tier, but I’m unsure how my existing boards, automation rules, and connected Slack workspace will be handled during the upgrade. Can you walk me through the steps and let me know if there’s any downtime or hidden fees involved?

100%|████████████████████████████████████████████| 1/1 [00:00<00:00, 141.51it/s]
100%|████████████████████████████████████████████| 5/5 [00:00<00:00, 244.61it/s]
Output

Here we can see that not only the results are irrelevant and scattered across the space, the query itself lands in an empty region in the space. This means that we don't have coverage for queries of this kind.

Identifying Clusters

The visualization can help us identify the clusters in our data. We can see that there are roughly 12 clusters in this space. Let's use scikit-learn to find them:

[131]

Next, we can take each embedding from our projected space and match it to the document from our dataset it represents. Then, since we have the clusters figured out, we can take a sample of 5 documents from each cluster, and let an LLM produce a category label for each cluster.

[132]

Finally, we can visualize the space with the labeled clusters:

[133]
(np.float64(-6.513811683654785),
, np.float64(17.91141757965088),
, np.float64(-6.976258444786072),
, np.float64(14.565848994255067))
Output