Search

115 code results for embeddings

Code
115

description: >-
How to build semantic search with embeddings for Val Town within Val Town
itself
features to come out of the world of machine learning: embeddings. It works like this: you put i
ding for their search query. Then we find the document embeddings that are closest to the query
That's the idea, though in practice embeddings can be quite unpredictable and surprising. Our ex
<figure style="max-width: 700px; margin: 0 auto">
<img src="https://assets.blog.val.town/legacy/val-vibes/compare-embeddings.png" alt="" />
<figcaption>
1. **Indexing**: generating embeddings for all public vals.
ing for the search query, and comparing to the indexed embeddings.
```sql
CREATE TABLE vals_embeddings (id TEXT PRIMARY KEY, embedding VECTOR(1536));
```
We filter out vals for which we have existing embeddings, put the rest in batches of 100 vals.
Then we fetch embeddings from OpenAI for each batch of 100 in parallel, and save them to Postgre
description: >-
How to build semantic search with embeddings for Val Town within Val Town
itself
features to come out of the world of machine learning: embeddings. It works like this: you put i
ding for their search query. Then we find the document embeddings that are closest to the query
That's the idea, though in practice embeddings can be quite unpredictable and surprising. Our ex
<figure style="max-width: 700px; margin: 0 auto">
<img src="https://assets.blog.val.town/legacy/val-vibes/compare-embeddings.png" alt="" />
<figcaption>
1. **Indexing**: generating embeddings for all public vals.
ing for the search query, and comparing to the indexed embeddings.
```sql
CREATE TABLE vals_embeddings (id TEXT PRIMARY KEY, embedding VECTOR(1536));
```
We filter out vals for which we have existing embeddings, put the rest in batches of 100 vals.
Then we fetch embeddings from OpenAI for each batch of 100 in parallel, and save them to Postgre
description: >-
How to build semantic search with embeddings for Val Town within Val Town
itself
features to come out of the world of machine learning: embeddings. It works like this: you put i
ding for their search query. Then we find the document embeddings that are closest to the query
That's the idea, though in practice embeddings can be quite unpredictable and surprising. Our ex
<figure style="max-width: 700px; margin: 0 auto">
<img src="https://assets.blog.val.town/legacy/val-vibes/compare-embeddings.png" alt="" />
<figcaption>
1. **Indexing**: generating embeddings for all public vals.
ing for the search query, and comparing to the indexed embeddings.
```sql
CREATE TABLE vals_embeddings (id TEXT PRIMARY KEY, embedding VECTOR(1536));
```
We filter out vals for which we have existing embeddings, put the rest in batches of 100 vals.
Then we fetch embeddings from OpenAI for each batch of 100 in parallel, and save them to Postgre
description: >-
How to build semantic search with embeddings for Val Town within Val Town
itself
features to come out of the world of machine learning: embeddings. It works like this: you put i
ding for their search query. Then we find the document embeddings that are closest to the query
That's the idea, though in practice embeddings can be quite unpredictable and surprising. Our ex
<figure style="max-width: 700px; margin: 0 auto">
<img src="https://assets.blog.val.town/legacy/val-vibes/compare-embeddings.png" alt="" />
<figcaption>
1. **Indexing**: generating embeddings for all public vals.
ing for the search query, and comparing to the indexed embeddings.
```sql
CREATE TABLE vals_embeddings (id TEXT PRIMARY KEY, embedding VECTOR(1536));
```
We filter out vals for which we have existing embeddings, put the rest in batches of 100 vals.
Then we fetch embeddings from OpenAI for each batch of 100 in parallel, and save them to Postgre
description: >-
How to build semantic search with embeddings for Val Town within Val Town
itself
features to come out of the world of machine learning: embeddings. It works like this: you put i
ding for their search query. Then we find the document embeddings that are closest to the query
That's the idea, though in practice embeddings can be quite unpredictable and surprising. Our ex
<figure style="max-width: 700px; margin: 0 auto">
<img src="https://assets.blog.val.town/legacy/val-vibes/compare-embeddings.png" alt="" />
<figcaption>
1. **Indexing**: generating embeddings for all public vals.
ing for the search query, and comparing to the indexed embeddings.
```sql
CREATE TABLE vals_embeddings (id TEXT PRIMARY KEY, embedding VECTOR(1536));
```
We filter out vals for which we have existing embeddings, put the rest in batches of 100 vals.
Then we fetch embeddings from OpenAI for each batch of 100 in parallel, and save them to Postgre
It does this by comparing [embeddings from OpenAI](https://platform.openai.com/docs/guides/embed
I implemented three backends, which you can switch between in the search UI. Check out these val
- **Neon:** storing and searching embeddings using the [pg_vector](https://neon.tech/docs/extens
- Searching: [janpaul123/semanticSearchNeon](https://www.val.town/v/janpaul123/semanticSearchN
- Indexing: [janpaul123/indexValsNeon](https://www.val.town/v/janpaul123/indexValsNeon)
- **Blobs:** storing embeddings in Val Town's [standard blob storage](https://docs.val.town/std/
- Searching: [janpaul123/semanticSearchBlobs](https://www.val.town/v/janpaul123/semanticSearch
);
const { OpenAIEmbeddings } = await import(
"https://esm.sh/langchain/embeddings/openai"
);
[{ id: 2 }, { id: 1 }, { id: 3 }],
new OpenAIEmbeddings({
openAIApiKey: process.env.OPENAI_API_KEY,
import { searchEmojis } from "https://esm.town/v/maxm/emojiVectorEmbeddings";
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
<br />
Built on Val Town with sqlite vector search and openai embeddings.
<br />
Uses vector embeddings to get "vibes" search on emojis
```
async function calculateEmbeddings(text) {
const url = `https://yawnxyz-ai.web.val.run/generate?embed=true&value=${encodeURIComponent(t
} catch (error) {
console.error('Error calculating embeddings:', error);
return null;
);
const { OpenAIEmbeddings } = await import(
"https://esm.sh/langchain/embeddings/openai"
);
[{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }],
new OpenAIEmbeddings({
openAIApiKey: process.env.OPENAI_API_KEY,
/**
* Call OpenAPI Embeddings api to vectorize a query string
* Returns an array of 1536 numbers
}): Promise<number[]> =>
fetchJSON("https://api.openai.com/v1/embeddings", {
method: "POST",
);
const { OpenAIEmbeddings } = await import(
"https://esm.sh/langchain/embeddings/openai"
);
[{ id: 2 }, { id: 1 }, { id: 3 }],
new OpenAIEmbeddings({
openAIApiKey: process.env.OPENAI_API_KEY,
async function generateEmbedding(text: string): Promise<number[]> {
const response = await openai.embeddings.create({
model: "text-embedding-ada-002",