How am I able to give a unique identifier to the embeddings when they get created? Using ConvexVectorStore
#4702
Replies: 1 comment 1 reply
-
Hey @achris-alonzo30! Great to see you back again. I hope you're doing wonderfully. 😊 Yes, there is a way to assign a unique key to the embeddings when they are stored in the ConvexVectorStore to isolate and filter the chat history and embeddings for each document. This can be achieved by modifying the namespace or key generation strategy used in the To isolate embeddings per document, you can append a unique identifier for each document to the namespace or modify the key generation logic to include document-specific information. This unique identifier could be a hash of the document's content, a UUID, or any other unique attribute associated with the document. By doing so, the Language Learning Model (LLM) can be directed to use only the embeddings associated with the current document's unique key, ensuring it does not retain or use answers from previous documents. Here's an illustrative modification to include a document-specific identifier in the namespace: // Assuming each document has a unique identifier, e.g., a hash or UUID
const documentId = "unique_document_identifier"; // This should be dynamically determined for each document
const cacheBackedEmbeddings = CacheBackedEmbeddings.fromBytesStore(
underlyingEmbeddings,
inMemoryStore,
{
namespace: `${underlyingEmbeddings.modelName}-${documentId}`,
}
); In this modification, The You can find more details in the LangChain JS source code: Please note that this approach assumes that you have a mechanism to manage and assign unique identifiers to each document. If you don't have such a mechanism in place, you might need to implement one. Also, keep in mind that changing the namespace or key generation strategy will affect how embeddings are stored and retrieved, so you should thoroughly test any changes to ensure they meet your requirements. Sources
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
// Code for creating the embeddings and storing it Convex Vectore Database.
export const createEmbeddings = internalAction({
args: {
storageFileId: v.id("_storage"),
},
handler: async (ctx, args) => {
let fileUrl = await ctx.storage.get(args.storageFileId);
})
export const answer = internalAction({
args: {
sessionId: v.string(),
message: v.string(),
fileId: v.id("_storage"),
},
handler: async (ctx, args) => {
const vectorStore = new ConvexVectorStore(new OpenAIEmbeddings(), { ctx });
const model = new ChatOpenAI({ modelName: OPENAI_MODEL, temperature: 0 });
},
});
Description
Use Case
I'm trying to find a way to add a unique key when I store the embeddings in the ConvexVectorStore, if that is possible?
Problem
I'm encountering an issue when I load a new document to start a new conversation the LLM still retains the answer from the previous document.
I also found when it try to search the embeddings to find the answer it also fetched the embeddings from the previous documents, I'm not sure if this what should happen?
Expectation
System Info
Dependencies
"dependencies": {
"@clerk/clerk-sdk-node": "^4.13.11",
"@clerk/nextjs": "^4.29.9",
"@hookform/resolvers": "^3.3.4",
"@instructor-ai/instructor": "^0.0.7",
"@langchain/openai": "^0.0.18",
"@langchain/pinecone": "^0.0.3",
"@pinecone-database/doc-splitter": "^0.0.1",
"@pinecone-database/pinecone": "^2.1.0",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7",
"@tanstack/react-table": "^8.13.2",
"ai": "^3.0.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"convex": "^1.10.0",
"date-fns": "^3.3.1",
"framer-motion": "^11.0.8",
"i": "^0.3.7",
"langchain": "^0.1.25",
"lucide-react": "^0.344.0",
"next": "14.1.1",
"next-themes": "^0.2.1",
"npm": "^10.5.0",
"openai": "^4.28.4",
"pdf-parse": "^1.1.1",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.51.0",
"react-loader-spinner": "^6.1.6",
"react-loading-skeleton": "^3.4.0",
"react-markdown": "^9.0.1",
"react-pdf": "^7.7.1",
"react-resize-detector": "^10.0.1",
"react-textarea-autosize": "^8.5.3",
"react-wrap-balancer": "^1.1.0",
"replicate": "^0.18.1",
"simplebar-react": "^3.2.4",
"svix": "^1.20.0",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.1.1",
"postcss": "^8",
"tailwindcss": "^3.3.0",
"typescript": "^5"
}
Platform
Mac
Beta Was this translation helpful? Give feedback.
All reactions