Closed valdo99 closed 4 months ago
Hey @valdo99! Great to see you diving into the trenches with LangChain JS again. Running into a bit of a snag, I see? Let's get to the bottom of it together!
Thank you for the detailed report. You're correct in your observation that the 'namespace' option is not directly handled by the PineconeStore.fromDocuments
method. Instead, it's passed to the constructor of PineconeStore
when creating a new instance. This means the 'namespace' specified in dbConfig
is used to initialize the PineconeStore
instance, affecting all operations performed by this instance, including adding documents.
The PineconeStore.addDocuments
method, on the other hand, does not directly handle the 'namespace' option itself. Instead, it delegates to the addVectors
method, which uses the 'namespace' that was set during the instantiation of the PineconeStore
object. This means the 'namespace' used in addDocuments
is the one that was specified when the PineconeStore
instance was created, and it cannot be changed or specified per call to addDocuments
.
Here's the relevant code for reference:
// PineconeStore.fromDocuments
static async fromDocuments(
docs: Document[],
embeddings: EmbeddingsInterface,
dbConfig: PineconeLibArgs
): Promise<PineconeStore> {
const args = dbConfig;
args.textKey = dbConfig.textKey ?? "text";
const instance = new this(embeddings, args);
await instance.addDocuments(docs);
return instance;
}
// PineconeStore.addDocuments
async addDocuments(
documents: Document[],
options?: { ids?: string[] } | string[]
) {
const texts = documents.map(({ pageContent }) => pageContent);
return this.addVectors(
await this.embeddings.embedDocuments(texts),
documents,
options
);
}
Your workaround of creating a new instance of PineconeStore
with the namespace, then using addDocuments
to add the documents in the right namespace is indeed the correct approach given the current design of the PineconeStore
class.
As for the issue of documents being upserted into the default namespace instead of the specified one, it suggests that either the 'namespace' was not correctly set during the instance creation or there's an issue in how the Pinecone API handles the namespace during the upsert operation. However, based on the provided code, the 'namespace' option is correctly passed and should be considered during the upsert operation.
I hope this clarifies the situation. If you have any further questions or need additional clarification, please don't hesitate to ask. Dosu
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
I'm trying to upsert documents into a specific pinecone namespace using
PineconeStore.fromDocuments
, it upserts the docs into the(default)
namespace of pinecone.fromDocuments
has this definition:where the interface
PineconeLibArgs
acceptsnamespace
in the following:BUT namespace its not being used when executing the HTTP request to pinecone.
I found a workaround: if i create a new instance of
PineconeStore
with the namespace, then I can useaddDocuments
to add the documents in the right namespaceI'll try to dive deeper on this and try to fix the issue!
System Info
"yarn info langchain" output too long :\
node v21.5.0, macos sonoma, M1 2020. yarn 1.22.19