Skip to content

Commit

Permalink
Embeddings bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
craigloewen-msft committed Mar 26, 2024
1 parent 9867b16 commit 6811e88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
41 changes: 19 additions & 22 deletions backendsrc/embeddingsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,43 @@ class embeddingsHandler {

constructor(inConfigObject) {
// Set up azureClient and Pinecone
this.azureClient = new OpenAIClient(inConfigObject.azureEndpointURL, new AzureKeyCredential(inConfigObject.azureOpenAIAPIKey), {apiVersion: "2023-05-15"});
this.azureClient = new OpenAIClient(inConfigObject.azureEndpointURL, new AzureKeyCredential(inConfigObject.azureOpenAIAPIKey), { apiVersion: "2023-05-15" });
this.pinecone = new Pinecone({
environment: "gcp-starter",
apiKey: inConfigObject.pineconeAPIKey,
});
this.index = this.pinecone.Index(embeddingsHandler.indexName);
this.maxConcurrentRequests = 1;
this.maxConcurrentRequests = 3;
this.pineconeSemaphore = new Semaphore(this.maxConcurrentRequests);
this.azureSemaphore = new Semaphore(this.maxConcurrentRequests);
}

async addEmbedding(inputIssue) {
try {
// Get embeddings from Azure OpenAI Embeddings model
const description = [GetDescription(inputIssue.title, inputIssue.body)];

// Get embeddings from Azure OpenAI Embeddings model
const description = [GetDescription(inputIssue.title, inputIssue.body)];
let embeddingObject = null;

let embeddingObject = null ;

try {
await this.azureSemaphore.runExclusive(async () => {
embeddingObject = await this.azureClient.getEmbeddings("issue-body-embeddings-model", description);
});
} catch (error) {
console.log(error);
}

let embedding = embeddingObject.data[0].embedding;
let embedding = embeddingObject.data[0].embedding;

let payload = {
id: inputIssue._id.toString(),
values: embedding,
}
let payload = {
id: inputIssue._id.toString(),
values: embedding,
}

console.log("Upserting embeddings for issue number: " + inputIssue.number);
return await this.pineconeSemaphore.runExclusive(async () => {
console.log("Semaphore acquired for issue number: " + inputIssue.number);
await this.index.namespace(inputIssue.repoRef.toString()).upsert([payload]);
});
return await this.pineconeSemaphore.runExclusive(async () => {
await this.index.namespace(inputIssue.repoRef.toString()).upsert([payload]);
});
} catch (error) {
console.error(error);
throw "Can't do embedding"
}
}


async removeEmbedding(inputIssue) {
await this.index.namespace(inputIssue.repoRef.toString()).deleteOne(inputIssue._id.toString());
Expand All @@ -67,7 +64,7 @@ class embeddingsHandler {
async getSimilarIssueIDs(repo, issueDescription, issue) {
// Create title + body description
const description = [issueDescription];

// Query azure for embeddings
const inputVector = await this.azureClient.getEmbeddings("issue-body-embeddings-model", description);

Expand Down
3 changes: 1 addition & 2 deletions backendsrc/refreshRepoHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ class RefreshRepoTask {
// Check if an issue was inserted
if (!updateResultRaw.lastErrorObject.updatedExisting) {
// Add inserted issue to list
let embeddingsPromise = this.embeddingsHandler.addEmbedding(updateResult);
finalAwaitPromiseArray.push(embeddingsPromise);
await this.embeddingsHandler.addEmbedding(updateResult);
}

if (updateResult.closed_by) {
Expand Down

0 comments on commit 6811e88

Please sign in to comment.