-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HNSWLib TypeError: Cannot read properties of undefined (reading 'embedQuery') #2528
Comments
🤖 Hello, From the error message you're seeing, it seems like the In your code, you're initializing Also, it's possible that the Here are a few things you can try:
I hope this helps. If you're still facing issues, please provide more details about the implementation of Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
🤖 Hello, I'm glad to hear that you were able to resolve the issue. To provide some clarification on why the embeddings object is necessary when loading a vector store with When you call static async load(directory: string, embeddings: Embeddings) {
const fs = await import("node:fs/promises");
const path = await import("node:path");
const args = JSON.parse(
await fs.readFile(path.join(directory, "args.json"), "utf8")
);
const index = await HNSWLib.getHierarchicalNSW(args);
const [docstoreFiles] = await Promise.all([
fs
.readFile(path.join(directory, "docstore.json"), "utf8")
.then(JSON.parse),
index.readIndex(path.join(directory, "hnswlib.index")),
]);
args.docstore = new SynchronousInMemoryDocstore(new Map(docstoreFiles));
args.index = index;
return new HNSWLib(embeddings, args);
} In this code, the embeddings object is passed to the new HNSWLib instance, which is then returned by the function. This ensures that the loaded vector store can correctly interpret the stored vectors. You can find this code in the HNSWLib source file. The I hope this clarifies your question. If you have any more questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Useful explanation, thank you. Whoever created this bot, make money with it! It's awesome! |
In my CLI tool, I've been using the examples in the docs to use HNSWLib to persist my in-memory store to disk and reload it every time the CLI command is run (instead of loading and embedding the docs every time).
What works:
.save()
)But then when I try to do anything with that store (e.g. run a similarity search or use it to execute a query in a chain call), it throws me the below error.
I have checked and I know the query is being passed in properly, and the embeddings object is really so simple I don't think it's possible to do anything wrong with it - at least the
new OpenAIEmbeddings()
thing was passed in normally, as per docs, but maybe I missed something?Code:
Output:
Note, it seems to complain, upon calling the chain, that there is no
embeddings
to use for embedding the query.But I gave it the OpenAI model, which did not complain when creating the store and embedding the documents in the first place. So not sure why it has a problem here.
Any advice would be appreciated.
Persisted store:

Embedded Documents definitely present:

For reference, this is how the store was saved down:
The text was updated successfully, but these errors were encountered: