Metadata-Version: 2.4
Name: langchain-cos-vectors
Version: 0.1.0
Summary: 腾讯云 COS 向量存储桶（CosVectors）的 LangChain VectorStore 集成。
Project-URL: Homepage, https://github.com/hushengquan/langchain-cos-vectors
Author: hushengquan
License: MIT
License-File: LICENSE
Requires-Python: >=3.10.0
Requires-Dist: cos-python-sdk-v5>=1.9.0
Requires-Dist: langchain-core<2.0.0,>=1.0.0
Requires-Dist: numpy>=1.26.2; python_version < '3.13'
Requires-Dist: numpy>=2.1.0; python_version >= '3.13'
Description-Content-Type: text/markdown

# langchain-cos-vectors

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

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

## 安装

```bash
pip install langchain-cos-vectors
```

## 快速开始

```python
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",
)
```

## 环境变量

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

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