---
title: Building AI-powered Article Embeddings with Chroma and GPT-4
description: This guide provides step-by-step instructions on using Chroma and GPT-4 to build AI-powered article embeddings for tasks like similarity-based search and recommendation systems.
url: /kb/guide/ai-powered-article-embeddings-with-chroma-and-gpt-4
canonical_url: "https://vercel.com/kb/guide/ai-powered-article-embeddings-with-chroma-and-gpt-4"
published: 2025-11-03
last_updated: 2025-11-10
authors: DX Team
related:
  - /docs/concepts/deployments/git
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---
<!-- docsgraph:related -->
## Related pages

> **For AI agents:** Follow these links to understand how this page connects to the rest of the Vercel ecosystem. For the full cross-link map (inbound, outbound, prerequisites, and semantic neighbors), see the .graph.md link below.

- [Vercel & OpenAI Integration](https://vercel.com/docs/agent-resources/integrations-for-models/openai?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — Integrate your Vercel project with OpenAI's powerful suite of models.
- [LangChain](https://vercel.com/docs/ai-gateway/ecosystem/framework-integrations/langchain?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — Learn how to integrate Vercel AI Gateway with LangChain to access multiple AI models through a unified interface
- [Getting started with Vercel](https://vercel.com/docs/getting-started-with-vercel?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — Install the Vercel CLI, add the Vercel Plugin or agent skills, and deploy your first project.
- [Vercel Deployment Guide](https://ai-sdk.dev/docs/advanced/vercel-deployment-guide?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related)
- [Building an AI Chatbot with Cohere, Next.js, and the Vercel AI SDK](https://vercel.com/kb/guide/cohere-nextjs-vercel-ai-sdk?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — Learn how to build a generative AI application using Cohere, Next.js, and Vercel.
- [How to Use ML Models from Hugging Face in Vercel Functions](https://vercel.com/kb/guide/ml-models-hugging-face?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — This guide provides step-by-step instructions on how to integrate ML models from Hugging Face into Vercel Functions
- [How to Deploy a Hexo Blog with Vercel](https://vercel.com/kb/guide/deploying-hexo-with-vercel?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — Create a Hexo blog and deploy it live with Vercel.
- [How to Deploy an Ember App with Vercel](https://vercel.com/kb/guide/deploying-ember-with-vercel?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — Create an Ember app and deploy it live with Vercel.
- [How to Deploy a Hugo Site with Vercel](https://vercel.com/kb/guide/deploying-hugo-with-vercel?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=related) — Create a Hugo website and deploy it live with Vercel.

Full cross-link map for this page: [/kb/guide/ai-powered-article-embeddings-with-chroma-and-gpt-4.graph.md](/kb/guide/ai-powered-article-embeddings-with-chroma-and-gpt-4.graph.md?from=related&source_path=%2Fkb%2Fguide%2Fai-powered-article-embeddings-with-chroma-and-gpt-4&source_site=vercel-kb&relationship=graph)
<!-- /docsgraph:related -->


## Introduction

This guide demonstrates how to use [Chroma](https://www.trychroma.com/), a developer-centric embedding database, along with GPT-4, a state-of-the-art language model. By following these steps, you can harness the power of Chroma and GPT-4 to enable similarity-based search, recommendation systems, and more.

## Prerequisites

Before proceeding with this guide, make sure you have the following prerequisites in place:

1. Docker installed on your machine.
   
2. An OpenAI API key.
   

## Guide

To get started with Chroma, follow the steps below:

### 1\. Install Chroma

Run the following command to install Chroma as a dependency in your project:

```text
npm install --save chromadb
```

### 2\. Get the Chroma Client

Import the ChromaClient from the \`chromadb\` package and create a new instance of the client:

```javascript
import { ChromaClient } from 'chromadb';

const client = new ChromaClient();
```

### 3\. Connect to Chroma's Backend

Before using Chroma, you need to connect to its backend. You can either connect to a hosted version of Chroma or run it on your local machine.

- Clone the Chroma repository from GitHub:
  

```text
git clone https://github.com/chroma-core/chroma.git
```

- Navigate to the cloned directory:
  

```text
cd chroma
```

- Start the Chroma backend using Docker Compose:
  

**Note:** Make sure Docker is running on your machine before doing so.

```text
docker-compose up -d --build
```

**Note**: If you encounter any build issues, please seek help in the active Community Discord, as most issues are resolved quickly.

### 4\. Create a Collection

Collections are used to store embeddings, documents, and metadata in Chroma. To create a collection, use the **`createCollection`** method of the Chroma client. Provide a name for the collection and an optional embedding function if you want to generate embeddings from text. Here's an example using OpenAI's `ada-002` model for embedding:

```javascript
import { OpenAIEmbeddingFunction } from 'chromadb';

const embedder = new OpenAIEmbeddingFunction({ openai_api_key: process.env.YOUR_API_KEY });
const collection = await client.createCollection({ name: "my_collection", embeddingFunction: embedder });
```

### 5\. Add Documents to the Collection

You can add text documents to the collection using the **`add`** method. Chroma will handle tokenization, embedding, and indexing automatically. You can add through raw text documents:

```javascript
await collection.add({
    ids: ["id1", "id2"],
    metadatas: [{ "source": "my_source" }, { "source": "my_source" }],
    documents: ["This is a document", "This is another document"],
});
```

Or by adding pre-computed embeddings:

```javascript
await collection.add({
    ids: ["id1", "id2"],
    embeddings: [[1.2, 2.3, 4.5], [6.7, 8.2, 9.2]],
    metadatas: [{ "source": "my_source" }, { "source": "my_source" }],
    documents: ["This is a document", "This is another document"]
});
```

### 6\. Query the Collection

You can query the collection to retrieve the most similar results based on a list of query texts or query embeddings. Use the **`query`** method of the collection object. Here's an example:

```javascript
const results = await collection.query({
    nResults: 2,
    queryTexts: ["This is a query document"]
});
```

### 7\. Deploy to Vercel

Finally, we’ll be deploying the repo to Vercel.

1\. First, create a new GitHub repository and push your local changes.

2\. [Deploy it to Vercel.](https://vercel.com/docs/concepts/deployments/git#deploying-a-git-repository) Ensure you add all environment variables that you configured earlier to Vercel during the import process.

And that's it! By following these steps, you can integrate Chroma and OpenAI GPT-4 into your application, allowing you to leverage powerful AI-powered article embeddings for various use cases.

Good luck with your AI-powered project!