Skip to content

Conversation

@zombieyang
Copy link
Contributor

@zombieyang zombieyang commented Apr 13, 2023

if I read some text from file by fs, sometime I will forget to pass 'utf-8' as arguments and get a Buffer.
And if I use this content to create a vectorStore, I will get a unreadable error message

const content = readFileSync(join(__dirname, 'input.txt'))  // should be readFileSync(join(__dirname, 'input.txt'), 'utf-8')
Chroma.fromTexts(
        [content],
        [{}],
        embeddingModel,
        {
            collectionName: "abc",
        }
    );


// will got this error
TypeError: t.replaceAll is not a function
    at file:///T:/_CODE_/langchain-test2/node_modules/langchain/dist/embeddings/openai.js:68:79
    at Array.map (<anonymous>)
    at OpenAIEmbeddings.embedDocuments (file:///T:/_CODE_/langchain-test2/node_modules/langchain/dist/embeddings/openai.js:68:66)
    at Chroma.addDocuments (file:///T:/_CODE_/langchain-test2/node_modules/langchain/dist/vectorstores/chroma.js:39:53)
    at Chroma.fromDocuments (file:///T:/_CODE_/langchain-test2/node_modules/langchain/dist/vectorstores/chroma.js:120:24)
    at Chroma.fromTexts (file:///T:/_CODE_/langchain-test2/node_modules/langchain/dist/vectorstores/chroma.js:116:23)
    at insertIntoChroma (file:///T:/_CODE_/langchain-test2/chroma.mjs:57:18)
    at run (file:///T:/_CODE_/langchain-test2/chroma.mjs:47:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

That is because langchain try to invoke replaceAll for the inputting Buffer.


This PR add a toString() invoke when creating a vectorstore by text. I don't know whether should we check the typeof text or use toString directly. If you think it is better to check the type and throw Error, plz let me know.

@vercel
Copy link

vercel bot commented Apr 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Apr 13, 2023 1:54pm

@zombieyang zombieyang changed the title add toString() in .fromTexts to prevent unreadability error message add toString() in .fromTexts to prevent unreadabe error message Apr 13, 2023
@zombieyang zombieyang changed the title add toString() in .fromTexts to prevent unreadabe error message add toString() in .fromTexts to prevent unreadable error message Apr 13, 2023
@nfcampos
Copy link
Collaborator

@nfcampos nfcampos added the question Further information is requested label Apr 13, 2023
@zombieyang zombieyang changed the title add toString() in .fromTexts to prevent unreadable error message add toString() in Document's ctor to prevent unreadable error message Apr 13, 2023
@zombieyang
Copy link
Contributor Author

Oh, that's way better. Thank you.
I force pushed my new commit.

@nfcampos nfcampos added lgtm PRs that are ready to be merged as-is and removed question Further information is requested labels Apr 13, 2023
@nfcampos
Copy link
Collaborator

Great, thank you!

@nfcampos nfcampos merged commit 638efbc into langchain-ai:main Apr 13, 2023
@jacobcwright
Copy link

This issue still occurs if not on Node 16+

@zombieyang
Copy link
Contributor Author

This issue still occurs if not on Node 16+

langchain.js declared a node version limitation in package.json.
https://github.com/hwchase17/langchainjs/blob/main/langchain/package.json#L7

I even cannot run any http request in node16. How can you run that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm PRs that are ready to be merged as-is

Projects

None yet

Development

Successfully merging this pull request may close these issues.

t.replaceAll is not a function when using "PineconeStore.fromDocuments"

3 participants