diff --git a/src/deleteEmbedding.ts b/src/deleteEmbedding.ts index 8a82ca2..732a108 100644 --- a/src/deleteEmbedding.ts +++ b/src/deleteEmbedding.ts @@ -1,3 +1,5 @@ +// This file is used to delete embeddings from the Pinecone index. The function deleteEmbeddings is defined and called to delete the embeddings from the Pinecone index. + // deleteEmbeddings.ts import { Pinecone } from "@pinecone-database/pinecone"; import dotenv from "dotenv"; diff --git a/src/generateEmbeddings.ts b/src/generateEmbeddings.ts index 35637b8..a85b7e2 100644 --- a/src/generateEmbeddings.ts +++ b/src/generateEmbeddings.ts @@ -1,3 +1,5 @@ +// The below code snippet is used to generate embeddings for the text data using the Google Generative AI API. The text data is split into chunks of 200 words each, and embeddings are generated for each chunk using the `embedContent` method of the `GoogleGenerativeAI` class. The embeddings are stored in an array along with the chunk index and text data for reference. The generated embeddings are then logged to the console and returned as an array. + // generateEmbeddings.js import { chunkText } from "./utils/chunkText"; // Adjust the path as necessary import data from "./data/data"; // Adjust the path as necessary diff --git a/src/queryEmbeddings.ts b/src/queryEmbeddings.ts index 56666d7..0060414 100644 --- a/src/queryEmbeddings.ts +++ b/src/queryEmbeddings.ts @@ -1,3 +1,5 @@ +// The below code snippet is used to query embeddings for a given text input using the Google Generative AI API and the Pinecone database. The queryEmbeddings function is defined to generate embeddings for the input text and query the Pinecone index for similar embeddings. The top 3 matches are returned as the query response. The getData function is defined to extract the text data from the query response. The generateAnswer function is defined to generate an answer based on the query text and context using the Google Generative AI API. The query text is used as the prompt for the answer generation process. + // queryEmbeddings.ts import { Pinecone } from "@pinecone-database/pinecone"; import { GoogleGenerativeAI } from "@google/generative-ai"; diff --git a/src/storeEmbeddings.ts b/src/storeEmbeddings.ts index 93439d4..d0b6bf0 100644 --- a/src/storeEmbeddings.ts +++ b/src/storeEmbeddings.ts @@ -1,3 +1,5 @@ +// The below code snippet is used to store embeddings in the Pinecone database. The storeEmbeddings function is defined to generate embeddings using the generateEmbeddings function and store them in the Pinecone index. The embeddings are upserted to the Pinecone index using the upsert method. The index is initialized with the specified dimension, metric, and serverless configuration. The storeEmbeddings function is then called to store the embeddings in the Pinecone database. + // storeEmbeddings.ts import { Pinecone } from "@pinecone-database/pinecone"; import dotenv from "dotenv"; diff --git a/src/utils/chunkText.ts b/src/utils/chunkText.ts index e8bbcbf..0236885 100644 --- a/src/utils/chunkText.ts +++ b/src/utils/chunkText.ts @@ -1,3 +1,5 @@ +// The below function is used to split the text into chunks of 200 words each. + export const chunkText = (text: string, chunkSize = 200) => { const words = text.split(/\s+/); const chunks: string[] = [];