Skip to content
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

TypeError: Converting circular structure to JSON when enabling LangSmith #5198

Open
5 tasks done
sinedied opened this issue Apr 24, 2024 · 2 comments
Open
5 tasks done
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@sinedied
Copy link
Contributor

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

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)

[api] [2024-04-23T15:11:38.138Z] TypeError: Converting circular structure to JSON
[api] [2024-04-23T15:11:38.138Z]     --> starting at object with constructor 'Socket'
[api] [2024-04-23T15:11:38.138Z]     |     property 'parser' -> object with constructor 'HTTPParser'
[api] [2024-04-23T15:11:38.138Z]     --- property 'socket' closes the circle
[api] [2024-04-23T15:11:38.138Z]     at JSON.stringify (<anonymous>)
[api] [2024-04-23T15:11:38.138Z]     at Client.batchIngestRuns (/Users/sinedied/projects/serverless-chat-langchainjs/node_modules/langsmith/dist/client.cjs:637:51)
[api] [2024-04-23T15:11:38.138Z]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[api] [2024-04-23T15:11:38.139Z]     at async Client.drainAutoBatchQueue (/Users/sinedied/projects/serverless-chat-langchainjs/node_modules/langsmith/dist/client.cjs:477:17)

Description

Trying to enable Langsmith, but the app crashes when trying to send the report.

System Info

npm ls langchain @langchain/comm
unity
[email protected] /Users/sinedied/projects/serverless-chat-langchainjs
└─┬ [email protected] -> ./packages/api
├── @langchain/[email protected] -> ./packages/api
└─┬ [email protected]
└── @langchain/[email protected] deduped -> ./packages/api

platform mac, node v20.11.0, npm 10.2.4

Copy link

dosubot bot commented Apr 24, 2024

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:

  1. 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.

  2. 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());
  3. 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.

Details

Sources


About Dosu
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.

To continue the conversation, mention @dosu.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Apr 24, 2024
@sinedied
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant