Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add createEmbeddingForPart function #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Jacksonmills
Copy link
Owner

This commit adds a new function createEmbeddingForPart to the chat API route. This function takes a part and creates an embedding using the OpenAI API. The result is an array of numbers. The function is used to calculate the cosine similarity between the user's input and various parts of a mecha.

The cosineSimilarity function has been added as well to calculate the cosine similarity between two arrays of numbers. The function checks if the lengths of the arrays are equal and appends zeros to the shorter array if needed. Then it calculates the dot product and norms of the arrays to determine the similarity.

The POST handler in the chat API route has been updated to use the new functions. It creates an embedding for the user's input and calculates the cosine similarity between the user's input and various parts of the mecha. It then selects the top 5 parts with the highest similarity scores and includes them in the response to the user.

In the page component, a new import statement has been added to import the parts module from the DB.

This commit adds a new function `createEmbeddingForPart` to the chat API route. This function takes a part and creates an embedding using the OpenAI API. The result is an array of numbers. The function is used to calculate the cosine similarity between the user's input and various parts of a mecha.

The cosineSimilarity function has been added as well to calculate the cosine similarity between two arrays of numbers. The function checks if the lengths of the arrays are equal and appends zeros to the shorter array if needed. Then it calculates the dot product and norms of the arrays to determine the similarity.

The POST handler in the chat API route has been updated to use the new functions. It creates an embedding for the user's input and calculates the cosine similarity between the user's input and various parts of the mecha. It then selects the top 5 parts with the highest similarity scores and includes them in the response to the user.

In the page component, a new import statement has been added to import the `parts` module from the DB.
@vercel
Copy link

vercel bot commented Aug 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ac-garage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2023 5:15pm

- The OpenAI model used for creating embeddings has been updated to 'text-embedding-ada-002'. This change ensures compatibility with the latest version of the model.
- Additionally, in the cosineSimilarity function, added a check to return 0 if either vector is not defined to denote no similarity.
- Updated import statement to include CreateEmbeddingResponse type
- Modified return type of createEmbeddingForPart function
- Renamed variables for clarity
- Modified cosineSimilarity function to accept and compare user embedding
- Updated variable names in POST function for consistency
- Updated cosineSimilarity function call in POST function to use userEmbedding
- Added console log statement to debug userEmbedding
…part embeddings

- Refactored the cosineSimilarity function to remove unnecessary conditional checks.
- Added console logs to print the user and part embeddings for debugging purposes.

These changes aim to improve code readability and aid in debugging any issues related to the embeddings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant