Tutorial
Indexing text with OpenAI embeddings using Vecal.
Tutorial: Indexing text with OpenAI embeddings
This tutorial shows how to build a small Hacker News search tool with Vecal and OpenAI embeddings. The complete code lives in src/main.ts
of the project.
- Obtain an OpenAI API key.
- Fetch the data you want to index.
- Convert each text item to an embedding using the OpenAI API.
- Create a
VectorDB
instance with the correct dimension and store each vector. - Perform searches with
db.search
ordb.annSearch
.
const db = new VectorDB({ dbName: 'hn-stories', dimension });
await db.add(embedding, { title: story.title, url: story.url });
const results = await db.search(queryEmbedding, 5);
Check the source file for the full working example.