Skip to content

Commit

Permalink
add support for multiple users with uuidv4
Browse files Browse the repository at this point in the history
  • Loading branch information
aliiyuu committed Aug 21, 2024
1 parent f4aa45e commit abf16e7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
14 changes: 8 additions & 6 deletions server/config/pineconeConfig/pineconeManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Pinecone } = require("@pinecone-database/pinecone");
const seed = require('../seedConfig');

/**
* PineconeManager is a class that encapsulates all operations related to managing
Expand Down Expand Up @@ -65,10 +66,10 @@ class PineconeManager {
*
* @async
* @param {Object} data - The dictionary of functions and classes with embeddings.
* @param {string} [namespace="codebase"] - The namespace in the index to upsert to.
* @param {string} [namespace=`codebase${seed}`] - The namespace in the index to upsert to.
* @returns {Promise<void>} A promise that resolves once the embeddings are upserted.
*/
async upsertEmbeddings(data, namespace = "codebase") {
async upsertEmbeddings(data, namespace = `codebase${seed}`) {
// Prepare the upsert request payload
const upsertPayload = [];

Expand Down Expand Up @@ -98,18 +99,19 @@ class PineconeManager {
await this.index.namespace(namespace).upsert(upsertPayload);
await this.delay(3000); // 3 second delay
console.log('Embeddings upserted successfully.');
// console.log(`Seed: ${seed}`);
}

/**
* Queries the Pinecone index using the provided embedding.
*
* @async
* @param {Array<number>} embedding - The embedding vector to query with.
* @param {string} [namespace="samplecode"] - The namespace to query.
* @param {string} [namespace=`codebase${seed}`] - The namespace to query.
* @param {number} [topK=5] - The number of top results to return.
* @returns {Promise<Object[]>} A promise that resolves to the query results.
*/
async similaritySearch(embedding, namespace = "codebase", topK = 3) {
async similaritySearch(embedding, namespace = `codebase${seed}`, topK = 3) {
const queryResponse = await this.index.namespace(namespace).query({
vector: embedding,
topK: topK, // Number of top results to return
Expand All @@ -136,10 +138,10 @@ class PineconeManager {
* Deletes the vectors in a specified namespace.
*
* @async
* @param {string} [namespace="ns1"] - The namespace in the index to search within.
* @param {string} [namespace=`codebase${seed}`] - The namespace in the index to search within.
* @returns {Promise<void>} A promise that resolves once all vectors in a namespace are deleted.
*/
async deleteVectorsFromNamespace(namespace) {
async deleteVectorsFromNamespace(namespace=`codebase${seed}`) {
await this.index.namespace(namespace).deleteAll();
}
}
Expand Down
10 changes: 10 additions & 0 deletions server/config/seedConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { v4: uuidv4 } = require('uuid');

function generateSeed() {
const seed = uuidv4();
return seed;
}

const userSeed = generateSeed();

module.exports = userSeed;
2 changes: 1 addition & 1 deletion server/controllers/deleteCodebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const deleteCodebase = async (req, res) => {
// Delete everything from the Pinecone namespace
const index = "syntaxsorcerer";
const namespace = "codebase"; // Default for our project
await pinecone.deleteVectorsFromNamespace(namespace);
await pinecone.deleteVectorsFromNamespace();


res.json({ message: "Codebase deleted" });
Expand Down
16 changes: 15 additions & 1 deletion server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"version": "1.0.0",
"main": "server.js",
"dependencies": {
"@pinecone-database/pinecone": "^3.0.0",
"adm-zip": "^0.5.5",
"axios": "^1.7.3",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.19.2",
"node-fetch": "^2.6.1",
"openai": "^4.55.5",
"@pinecone-database/pinecone": "^3.0.0",
"tree-sitter": "^0.21.1",
"tree-sitter-cli": "^0.22.6",
"tree-sitter-javascript": "^0.21.4"
"tree-sitter-javascript": "^0.21.4",
"uuid": "^10.0.0"
},
"scripts": {
"start": "node server.js",
Expand Down

0 comments on commit abf16e7

Please sign in to comment.