langchain-ai / langchainjs

πŸ¦œπŸ”— Build context-aware reasoning applications πŸ¦œπŸ”—
https://js.langchain.com/docs/
MIT License
11.93k stars 2k forks source link

Cassandra Chat Memory TypeError, indicating that "Contacts points are not defined." #4190

Closed natapol2547 closed 5 months ago

natapol2547 commented 5 months ago

Description: The Langchain JS Cassandra Chat Memory documentation specifies a configuration for connecting to Cassandra using the cassandra-driver. However, when attempting to use this configuration, it results in a TypeError, indicating that "Contacts points are not defined." I am using Astra DB

Code to Reproduce:

const configConnection = {
  serviceProviderArgs: {
    astra: {
      token: "<your Astra Token>" as string,
      endpoint: "<your Astra Endpoint>" as string,
    },
  },
};

const memory = new BufferMemory({
  chatHistory: new CassandraChatMessageHistory({
    ...configConnection,
    keyspace: "langchain",
    table: "message_history",
    sessionId: "<some unique session identifier>",
  }),
});

Error Log:

TypeError: Contacts points are not defined.
    at Object.extend (C:\Users\...\node_modules\.pnpm\cassandra-driver@4.7.2\node_modules\cassandra-driver\lib\client-options.js:120:13)
    at new Client (C:\Users\...\node_modules\.pnpm\cassandra-driver@4.7.2\node_modules\cassandra-driver\lib\client.js:402:32)
    at new CassandraChatMessageHistory (file:///C:/Users/.../node_modules/.pnpm/@langchain+community@0.0.20_@datastax+astra-db-ts@0.1.4_@pinecone-database+pinecone@2.0.1_cas_jikza335ii3jk2j2qigxowhicm/node_modules/@langchain/community/dist/stores/message/cassandra.js:85:23)
...

Additional Information: Langchain JS version: 0.1.9 cassandra-driver version: 4.7.2

natapol2547 commented 5 months ago

On the other hand, I should ask for a feature request for integration with Astra DB Chat Memory like Langchain Python has Link. It would use the astra-db-ts library instead. It would be awesome if we have that 😊

dosubot[bot] commented 5 months ago

πŸ€–

Hello @natapol2547! I'm Dosu, a friendly bot here to assist you while we wait for a human maintainer. I can help you with bug fixes, answer questions, and guide you on your journey to becoming a contributor. Let's tackle this issue together.

The "Contact points are not defined" error typically occurs when the Cassandra driver is unable to find the contact points or nodes of the Cassandra cluster. In your case, it seems like you're using a secure connection bundle to connect to the Cassandra cluster, which should contain the necessary contact points.

However, if you're still encountering this error, it might be due to an incorrect or missing secure connection bundle. Make sure the path to your secure bundle is correct and the bundle file is present at that location.

As for the integration with Astra DB Chat Memory using the astra-db-ts library, the current version of LangChain JS (0.1.9) does not support this feature. However, you can extend the BufferMemory class to use the astra-db-ts library for storing chat history. Here's a basic example:

import { BufferMemory } from "langchain/memory";
import { AstraChatMessageHistory } from "<path to your AstraChatMessageHistory class>";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { ConversationChain } from "langchain/chains";

const memory = new BufferMemory({
  chatHistory: new AstraChatMessageHistory({
    cloud: {
      secureConnectBundle: "<path to your secure bundle>",
    },
    credentials: {
      username: "token",
      password: "<your Astra DB access token>",
    },
    keyspace: "langchain",
    table: "message_history",
    sessionId: "<some unique session identifier>",
  }),
});

const model = new ChatOpenAI();
const chain = new ConversationChain({ llm: model, memory });

In this example, AstraChatMessageHistory is a hypothetical class that you would need to implement, which uses the astra-db-ts library to interact with Astra DB. Please note that this is a high-level example and the actual implementation may vary based on the specifics of your application and the astra-db-ts library.

Regarding your question about the expected format and content of the serviceProviderArgs object in the configConnection when using the CassandraChatMessageHistory class, I wasn't able to find an answer within the repository. Could you provide more details about the error or issue you're encountering with this object? This would help me provide a more accurate answer.

For more information, you can refer to the examples/src/memory/cassandra-store.ts file in the langchainjs repository.

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.

nicoloboschi commented 5 months ago

@natapol2547

AstraDB is supported by CassandraChatMessageHistory and it works for me. I'm using LangChain community @0.0.32

            const configConnection = {
                serviceProviderArgs: {
                    astra: {
                        token: "AstraCS:zzz",
                        endpoint: "https://fxxx.apps.astra.datastax.com"
                    },
                },
            };

            const chatHistory = new CassandraChatMessageHistory({
                ...configConnection,
                keyspace: "default_keyspace",
                table: "message_history",
                sessionId: "yyy",
            })
            chatHistory.addMessage(new AIMessage("test?"))

Agreed about the having AstraDB integration! But the current cassandra one is still compatible

mfortman11 commented 5 months ago

@natapol2547 AstraDBChatMessageHistory was added as part of 0.1.21

natapol2547 commented 5 months ago

@mfortman11 Ohh Thank you so much for mentioning me! I'll close this issue now. 😊