Skip to content

Commit

Permalink
Update 1-openai.mdx
Browse files Browse the repository at this point in the history
Correct path to openai.ts and updated code to match what's currently in GitHub
  • Loading branch information
68wooley authored Feb 26, 2024
1 parent 93dcd94 commit f2ea68d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions docs/7-vector-search/5-create-vectors/1-openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,25 @@ To query the data, Vector Search will need to calculate the distance between the

To do so, you will need to vectorize your query. You can use the same function to vectorize your query as well.

In the library application, we've created a function that will vectorize your query for you. You can find it in the `server/embeddings/openai.mjs` file.
In the library application, we've created a function that will vectorize your query for you. You can find it in the `server/src/embeddings/openai.ts` file.

```js
import OpenAI from 'openai';

const { OPENAI_API_KEY } = process.env;
const { EMBEDDING_KEY } = process.env;

const openai = new OpenAI({apiKey: OPENAI_API_KEY});
let openai;

const getEmbeddings = async (text) => {
const embeddings = await openai.embeddings.create({
model: "text-embedding-ada-002",
input: text,
});

return embeddings?.data[0]?.embeddings;
}
const getTermEmbeddings = async (text) => {
if (!openai) {
openai = new OpenAI({apiKey: EMBEDDING_KEY});
}
const embeddings = await openai.embeddings.create({
model: 'text-embedding-ada-002',
input: text,
});
return embeddings?.data[0]?.embedding;
};

export default getTermEmbeddings;
```
Expand Down

0 comments on commit f2ea68d

Please sign in to comment.