Open sinedied opened 2 months ago
To address the "TypeError: Converting circular structure to JSON" issue you're encountering with LangSmith, particularly in the context of AzureCosmosDBVectorStore
, the problem likely stems from a circular reference within the objects being serialized. Here's a focused approach to tackle this:
Identify and Debug Circular References: Utilize console.log()
or Node.js's util.inspect()
to inspect objects just before serialization. This can help pinpoint where the circular reference occurs.
Custom Replacer for JSON.stringify(): Implement a custom replacer function to handle circular references during JSON serialization. Here's a concise example:
function getCircularReplacer() {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
}
JSON.stringify(obj, getCircularReplacer());
Apply and Test: After applying the above solution, thoroughly test to ensure the issue is resolved without side effects.
The error trace you provided points to Client.batchIngestRuns
, suggesting the issue might not be directly within AzureCosmosDBVectorStore
but possibly in the objects it handles or the method itself. Apply the debugging steps to this area as well.
If the problem persists, providing more details about the operations leading to the error could help in offering a more specific solution.
To continue the conversation, mention @dosu.
Ok, removing entirely AzureCosmosDBVectorStore
from the chain did not solve the issue. I still get that error, but it cannot be reproduced all the time. Not sure how I should go to debug this or help debugging this?
Heyhey, can you provide the code sample for this? What does your wrappedFunc look like?
Yes, I could reproduce the error on this sample/branch: https://github.com/Azure-Samples/serverless-chat-langchainjs/tree/mongodb-vcore
I'm currently off till next week, I'll try to create a simpler repo for reproducing the issue.
Checked other resources
Example Code
The issue occurs when enabling Langsmith on this sample, in particular the Azure path: https://github.com/Azure-Samples/serverless-chat-langchainjs
The issue seems to come from the
AzureCosmosDBVectorStore
. I'm trying to investigate what could be the cause of the circular structure, do you have any hint on how to debug which object is the root cause?Error Message and Stack Trace (if applicable)
Description
Trying to enable Langsmith, but the app crashes when trying to send the report.
System Info
npm ls langchain @langchain/comm unity serverless-chat-langchainjs@1.0.0 /Users/sinedied/projects/serverless-chat-langchainjs └─┬ api@1.0.0 -> ./packages/api ├── @langchain/community@0.0.51 -> ./packages/api └─┬ langchain@0.1.35 └── @langchain/community@0.0.51 deduped -> ./packages/api
platform mac, node v20.11.0, npm 10.2.4