-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from pinecone-io/update-to-use-azure-serverless
Updated to use Azure serverless as the default Pinecone option.
- Loading branch information
Showing
6 changed files
with
43 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,33 @@ | ||
import { Pinecone, type ScoredPineconeRecord } from "@pinecone-database/pinecone"; | ||
import { connectPinecone, getOrCreateIndex, INDEX_NAME } from "@/lib/pinecone"; | ||
|
||
export type Metadata = { | ||
url: string, | ||
text: string, | ||
chunk: string, | ||
hash: string | ||
} | ||
import { connectPinecone, getOrCreateIndex, INDEX_NAME } from '@/lib/pinecone' | ||
|
||
// The function `getMatchesFromEmbeddings` is used to retrieve matches for the given embeddings | ||
const getMatchesFromEmbeddings = async (embeddings: number[], topK: number, namespace: string): Promise<ScoredPineconeRecord<Metadata>[]> => { | ||
const getMatchesFromEmbeddings = async ( | ||
embeddings: number[], | ||
topK: number, | ||
namespace: string | ||
) => { | ||
// Obtain a client for Pinecone | ||
const pinecone = await connectPinecone(); | ||
const pinecone = await connectPinecone() | ||
|
||
// Get the Pinecone index | ||
const index = await getOrCreateIndex(pinecone, INDEX_NAME); | ||
const index = await getOrCreateIndex(pinecone, INDEX_NAME) | ||
|
||
// Get the namespace | ||
const pineconeNamespace = index.namespace(namespace ?? '') | ||
// console.log("embeddings", JSON.stringify(embeddings)) | ||
|
||
try { | ||
// Query the index with the defined request | ||
const queryResult = await pineconeNamespace.query({ | ||
vector: embeddings, | ||
topK, | ||
includeMetadata: true, | ||
includeMetadata: true | ||
}) | ||
return queryResult.matches || [] | ||
} catch (e) { | ||
// Log the error and throw it | ||
console.log("Error querying embeddings: ", e) | ||
console.log('Error querying embeddings: ', e) | ||
throw new Error(`Error querying embeddings: ${e}`) | ||
} | ||
} | ||
|
||
export { getMatchesFromEmbeddings }; | ||
|
||
export { getMatchesFromEmbeddings } |