无法连接到Cassandra(AstraDB),用于LangChain文档中的矢量搜索示例

jmo0nnb3  于 2023-10-18  发布在  Cassandra
关注(0)|答案(1)|浏览(184)

我试图连接到AstraDB用于我的Python矢量搜索项目(用于我的GPT聊天机器人),但我收到了一个连接错误。(我遵循LangChain Cassandra Vector store示例中的示例,并希望使用AstraDB作为我的矢量数据库。
下面是我的代码:

  1. ASTRA_DB_CLIENT_ID = os.getenv("ASTRA_DB_CLIENT_ID")
  2. ASTRA_DB_APPLICATION_TOKEN = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
  3. ASTRA_DB_SECURE_BUNDLE_PATH = (
  4. "/Users/devin.bost/proj/demos/ACI/secure-connect-vector-demo.zip"
  5. )
  6. cluster = Cluster(
  7. cloud={
  8. "secure_connect_bundle": ASTRA_DB_SECURE_BUNDLE_PATH,
  9. },
  10. auth_provider=PlainTextAuthProvider(
  11. ASTRA_DB_CLIENT_ID,
  12. ASTRA_DB_APPLICATION_TOKEN,
  13. ),
  14. )
  15. session = cluster.connect()

我已经将ASTRA_DB_CLIENT_ID设置为特定的CLIENT_ID,并对其他环境变量执行了相同的操作。
我得到这个错误:

  1. Traceback (most recent call last):
  2. File "cassandra/cluster.py", line 1703, in cassandra.cluster.Cluster.connect
  3. File "cassandra/cluster.py", line 1690, in cassandra.cluster.Cluster.connect
  4. File "cassandra/cluster.py", line 3488, in cassandra.cluster.ControlConnection.connect
  5. File "cassandra/cluster.py", line 3533, in cassandra.cluster.ControlConnection._reconnect_internal
  6. cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'1d0ba879-1c8b-49e4-bc78-90baff9e5714-westus3.db.astra.datastax.com:29042:4cc2a061-0383-4355-85cd-699b4a5af93c': AuthenticationFailed('Failed to authenticate to 1d0ba879-1c8b-49e4-bc78-90baff9e5714-westus3.db.astra.datastax.com:29042:4cc2a061-0383-4355-85cd-699b4a5af93c: Error from server: code=0100 [Bad credentials] message="We recently improved your database security. To find out more and reconnect, see https://docs.datastax.com/en/astra/docs/manage-application-tokens.html"'), '1d0ba879-1c8b-49e4-bc78-90baff9e5714-westus3.db.astra.datastax.com:29042:a856cbcf-1faa-4098-84a0-94e221931fd8': AuthenticationFailed('Failed to authenticate to 1d0ba879-1c8b-49e4-bc78-90baff9e5714-westus3.db.astra.datastax.com:29042:a856cbcf-1faa-4098-84a0-94e221931fd8: Error from server: code=0100 [Bad credentials] message="We recently improved your database security. To find out more and reconnect, see https://docs.datastax.com/en/astra/docs/manage-application-tokens.html"'), '1d0ba879-1c8b-49e4-bc78-90baff9e5714-westus3.db.astra.datastax.com:29042:6f9150b3-c81a-4fcd-a61a-499ab11f09e8': AuthenticationFailed('Failed to authenticate to 1d0ba879-1c8b-49e4-bc78-90baff9e5714-westus3.db.astra.datastax.com:29042:6f9150b3-c81a-4fcd-a61a-499ab11f09e8: Error from server: code=0100 [Bad credentials] message="We recently improved your database security. To find out more and reconnect, see https://docs.datastax.com/en/astra/docs/manage-application-tokens.html"')})
  7. python-BaseException

我已经仔细检查了凭证,确保它们没有作为空值传递给对象,验证了安全捆绑包对于DB是正确的,安全捆绑包路径是正确的,并确保令牌配置了足够的权限。会是什么问题呢?

gopyfrb3

gopyfrb31#

问题是,当您将ASTRA_DB_CLIENT_ID从“token”更改为实际的CLIENT_ID时,实际上违反了示例。
如果你想使用token而不是客户端ID和secret,你需要将该参数设置为“token”,就像这样:

  1. auth_provider=PlainTextAuthProvider(
  2. "token",
  3. ASTRA_DB_APPLICATION_TOKEN,
  4. ),

一般来说,每当凭据不正确时,都可能引发异常。
或者,在建立连接时,您可以使用客户端ID和客户端密码。下面是使用这种方法的更完整的示例(使用您的代码):

  1. ASTRA_DB_CLIENT_ID = os.getenv("ASTRA_DB_CLIENT_ID")
  2. ASTRA_DB_APPLICATION_TOKEN = os.getenv("ASTRA_DB_APPLICATION_TOKEN")
  3. ASTRA_DB_SECURE_BUNDLE_PATH = (
  4. "/Users/devin.bost/proj/demos/ACI/secure-connect-vector-demo.zip"
  5. )
  6. cluster = Cluster(
  7. cloud={
  8. "secure_connect_bundle": ASTRA_DB_SECURE_BUNDLE_PATH,
  9. },
  10. auth_provider=PlainTextAuthProvider(
  11. ASTRA_DB_CLIENT_ID,
  12. ASTRA_DB_SECRET,
  13. ),
  14. )
  15. session = cluster.connect()

从官方的AstraDB门户网站上看到这个例子,相关部分用红色表示:

展开查看全部

相关问题