---
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
---

## 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!