Skip to main content

腾讯云 COS 向量存储桶(CosVectors)的 LangChain VectorStore 集成。

Project description

langchain-cos-vectors

腾讯云 COS 向量存储桶(CosVectors)的 LangChain VectorStore 集成。

CosVectors 是腾讯云对象存储(COS)推出的向量存储桶产品,支持向量的存储、检索和相似度搜索。

安装

pip install langchain-cos-vectors

快速开始

from langchain_cos_vectors import CosVectors
from langchain_openai import OpenAIEmbeddings

# 方式一:通过构造函数创建
cos_vectors = CosVectors(
    embedding=OpenAIEmbeddings(),
    cos_config={
        "Region": "ap-beijing",
        "SecretId": "your-secret-id",
        "SecretKey": "your-secret-key",
    },
    bucket="your-vector-bucket",
    index="your-index",
    endpoint="vectors.ap-beijing.coslake.com",  # 可选,自定义 Endpoint
)

# 添加文本
ids = cos_vectors.add_texts(
    texts=["hello world", "foo bar"],
    metadatas=[{"source": "test"}, {"source": "test"}],
)

# 相似度搜索
docs = cos_vectors.similarity_search("hello", k=2)

# 方式二:通过 from_texts 快速创建
cos_vectors = CosVectors.from_texts(
    texts=["hello", "world"],
    embedding=OpenAIEmbeddings(),
    cos_region="ap-beijing",
    cos_secret_id="your-secret-id",
    cos_secret_key="your-secret-key",
    bucket="my-vector-bucket",
    index="my-index",
    endpoint="vectors.ap-beijing.coslake.com",
)

环境变量

也可以通过环境变量配置认证信息:

export COS_SECRET_ID="your-secret-id"
export COS_SECRET_KEY="your-secret-key"
export COS_REGION="ap-beijing"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_cos_vectors-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_cos_vectors-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_cos_vectors-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_cos_vectors-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for langchain_cos_vectors-0.1.0.tar.gz
Algorithm Hash digest
SHA256 adfaf125bef7c7712798ea41b35fe89693f211f1392f5d2dc0001b9be934c834
MD5 89d7eeb77c1602e7f2f139e5f9d14b0a
BLAKE2b-256 b12b857e4da323e9144440d602db3868b86337906bba0ea35389c53e079975ad

See more details on using hashes here.

File details

Details for the file langchain_cos_vectors-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_cos_vectors-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8597a55df00996762d074b80636a55d1a971cf6f478db13925811309d2d0cb98
MD5 d2d51fcc19900343991080e8c771a075
BLAKE2b-256 d31be8857e02bf1d1b91fbbe66867b0d5a91b17b47bd8ebd721bdff5c875f142

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page