Apache License 2.0

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

AI-Northstar-Tech/vector-io:全矢量数据工具的通用接口

项目背景与痛点

随着大数据和机器学习的发展,矢量数据库和推荐算法平台逐渐成为数据驱动型应用的基础设施。市面上已有的矢量数据库,如 Faiss、Milvus 等,尽管在特定场景下表现优异,但它们各自的数据格式和交互接口差异显著,导致用户在数据交换和集成时需要消耗大量时间和资源。“AI-Northstar-Tech/vector-io” 应运而生,旨在解决跨矢量数据库的数据操作问题,提供一个统一的接口来处理这些平台的数据,实现无缝导入、导出和备份等功能。

核心技术揭秘

架构解析

矢量数据工具的设计远远超出了简单的文件操作层面。它需要处理多种类型的数据集,并且能够将数据无缝导入和导出到不同平台。该工具背后的技术栈包括各类语言的API接口设计与实现,多种数据格式的兼容性,以及在数据流上的高效与可靠的处理逻辑。以下是该工具一个简化版的数据流图示例:

graph TD A[用户请求] --> B{"参数校验"} B -->|"通过"| C[执行业务] C --> D{"数据类型检测"} D -->|"数据库"| E[/导入数据库/] D -->|"文件"| F[/导出文件/] B -->|"失败"| G[返回错误]

从图中可见,系统首先对接收到的用户请求进行参数校验,确保请求的有效性;一旦通过校验,系统则进一步检查数据的类型,并根据类型执行相关的业务逻辑。不论是导入数据库还是导出文件,系统都能高效地完成数据操作,保证整个流程顺畅。

实现原理

为了提供一个通用的数据处理接口,vector-io 使用了封闭系统设计原则,确保各个数据操作模块之间严格隔离,只通过统一的接口进行交互。充分利用了设计模式中的工厂模式,动态选择合适的处理组件来处理特定类型的数据。为了确保数据流的可靠性,vector-io 还实现了完备的数据校验和回滚机制,保证在任何情况下都能保持数据的一致性和完整性。

功能亮点与差异

相比同类工具,vector-io 主打简单易用和高度兼容性的特点。其核心功能是无缝适配各种矢量数据库和数据集,提供简洁而强大的数据处理接口。另外,它支持使用任意模型进行再嵌入操作,极大地提高了在不同模型下数据使用与切换的便捷性。

应用场景与落地建议

在实际生产环境下使用 vector-io,开发者需注意以下几点:

  • 数据量控制:对于大规模数据操作,建议分批处理,避免一次性操作带来性能问题。
  • 错误处理机制:要确保在数据流操作中具有有效的错误处理策略,特别是在数据导入、导出过程中的数据完整性检查。

此工具非常适合拥有复杂数据结构,需要频繁数据导入导出或备份恢复的数据驱动型项目。

综合评价

优点:

  • 高度的灵活性与强大的数据兼容性。
  • 通过统一接口极大地简化了跨平台数据操作的复杂度。
  • 自带完整且高效的数据处理机制,保障数据操作的可靠性。

缺点:

  • 对于初学者而言,可能会要求一定的技术门槛,需要熟悉矢量数据库相关概念。
  • 由于功能丰富复杂,更新频率可能较高,用户需保持对版本迭代的支持。

总体来说,“AI-Northstar-Tech/vector-io” 仍然是处理矢量数据的强大武器,适用于处理各类复杂的数据集合工作的团队和个人。

关于

GitHub 原始描述(英文)

Comprehensive Vector Data Tooling. The universal interface for all vector database, datasets and RAG platforms. Easily export, import, backup, re-embed (using any model) or access your vector data from any vector databases or repository.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

HTML
Jupyter Notebook
Python
Ruby
Shell

README

All Contributors

PyPI - Version PyPI - Downloads Discord Discord Badge

This library uses a universal format for vector datasets to easily export and import data from all vector databases.

Request support for a VectorDB by voting/commenting on this poll

See the Contributing section to add support for your favorite vector database.

Supported Vector Databases

Fully Supported

Vector Database Import Export
Pinecone ✅ ✅
Qdrant ✅ ✅
Milvus ✅ ✅
GCP Vertex AI Vector Search ✅ ✅
KDB.AI ✅ ✅
LanceDB ✅ ✅
DataStax Astra DB ✅ ✅
Chroma ✅ ✅
Turbopuffer ✅ ✅

Partial
Vector Database Import Export

In Progress
Vector Database Import Export
Azure AI Search ❌ ❌
Weaviate ❌ ❌
MongoDB Atlas ❌ ❌
OpenSearch ❌ ❌
Apache Cassandra ❌ ❌
txtai ❌ ❌
pgvector ❌ ❌
SQLite-VSS ❌ ❌

Not Supported
Vector Database Import Export
Vespa ❌ ❌
Marqo ❌ ❌
Elasticsearch ❌ ❌
Redis Search ❌ ❌
ClickHouse ❌ ❌
USearch ❌ ❌
Rockset ❌ ❌
Epsilla ❌ ❌
Activeloop Deep Lake ❌ ❌
ApertureDB ❌ ❌
CrateDB ❌ ❌
Meilisearch ❌ ❌
MyScale ❌ ❌
Neo4j ❌ ❌
Nuclia DB ❌ ❌
OramaSearch ❌ ❌
Typesense ❌ ❌
Anari AI ❌ ❌
Vald ❌ ❌
Apache Solr ❌ ❌

Installation

Using pip

pip install vdf-io

From source

git clone https://github.com/AI-Northstar-Tech/vector-io.git
cd vector-io
pip install -r requirements.txt

Universal Vector Dataset Format (VDF) specification

  1. VDF_META.json: It is a json file with the following schema VDFMeta defined in src/vdf_io/meta_types.py:
class NamespaceMeta(BaseModel):
    namespace: str
    index_name: str
    total_vector_count: int
    exported_vector_count: int
    dimensions: int
    model_name: str | None = None
    vector_columns: List[str] = ["vector"]
    data_path: str
    metric: str | None = None
    index_config: Optional[Dict[Any, Any]] = None
    schema_dict: Optional[Dict[str, Any]] = None


class VDFMeta(BaseModel):
    version: str
    file_structure: List[str]
    author: str
    exported_from: str
    indexes: Dict[str, List[NamespaceMeta]]
    exported_at: str
    id_column: Optional[str] = None

  1. Parquet files/folders for metadata and vectors.

Export Script

export_vdf --help
usage: export_vdf [-h] [-m MODEL_NAME]
                  [--max_file_size MAX_FILE_SIZE]
                  [--push_to_hub | --no-push_to_hub]
                  [--public | --no-public]
                  {pinecone,qdrant,kdbai,milvus,vertexai_vectorsearch}
                  ...

Export data from various vector databases to the VDF format for vector datasets

options:
  -h, --help            show this help message and exit
  -m MODEL_NAME, --model_name MODEL_NAME
                        Name of model used
  --max_file_size MAX_FILE_SIZE
                        Maximum file size in MB (default:
                        1024)
  --push_to_hub, --no-push_to_hub
                        Push to hub
  --public, --no-public
                        Make dataset public (default:
                        False)

Vector Databases:
  Choose the vectors database to export data from

  {pinecone,qdrant,kdbai,milvus,vertexai_vectorsearch}
    pinecone            Export data from Pinecone
    qdrant              Export data from Qdrant
    kdbai               Export data from KDB.AI
    milvus              Export data from Milvus
    vertexai_vectorsearch
                        Export data from Vertex AI Vector
                        Search

Import script

import_vdf --help
usage: import_vdf [-h] [-d DIR] [-s | --subset | --no-subset]
                  [--create_new | --no-create_new]
                  {milvus,pinecone,qdrant,vertexai_vectorsearch,kdbai}
                  ...

Import data from VDF to a vector database

options:
  -h, --help            show this help message and exit
  -d DIR, --dir DIR     Directory to import
  -s, --subset, --no-subset
                        Import a subset of data (default: False)
  --create_new, --no-create_new
                        Create a new index (default: False)

Vector Databases:
  Choose the vectors database to export data from

  {milvus,pinecone,qdrant,vertexai_vectorsearch,kdbai}
    milvus              Import data to Milvus
    pinecone            Import data to Pinecone
    qdrant              Import data to Qdrant
    vertexai_vectorsearch
                        Import data to Vertex AI Vector Search
    kdbai               Import data to KDB.AI

Re-embed script

This Python script is used to re-embed a vector dataset. It takes a directory of vector dataset in the VDF format and re-embeds it using a new model. The script also allows you to specify the name of the column containing text to be embedded.

reembed_vdf --help
usage: reembed_vdf [-h] -d DIR [-m NEW_MODEL_NAME]
                  [-t TEXT_COLUMN]

Reembed a vector dataset

options:
  -h, --help            show this help message and exit
  -d DIR, --dir DIR     Directory of vector dataset in
                        the VDF format
  -m NEW_MODEL_NAME, --new_model_name NEW_MODEL_NAME
                        Name of new model to be used
  -t TEXT_COLUMN, --text_column TEXT_COLUMN
                        Name of the column containing
                        text to be embedded

Examples

export_vdf -m hkunlp/instructor-xl --push_to_hub pinecone --environment gcp-starter

import_vdf -d /path/to/vdf/dataset milvus

reembed_vdf -d /path/to/vdf/dataset -m sentence-transformers/all-MiniLM-L6-v2 -t title

Follow the prompt to select the index and id range to export.

Contributing

Adding a new vector database

If you wish to add an import/export implementation for a new vector database, you must also implement the other side of the import/export for the same database. Please fork the repo and send a PR for both the import and export scripts.

Steps to add a new vector database (ABC):

  1. Add your database name in src/vdf_io/names.py in the DBNames enum class.
  2. Create new files src/vdf_io/export_vdf/export_abc.py and src/vdf_io/import_vdf/import_abc.py for the new DB.

Export:

  1. In your export file, define a class ExportABC which inherits from ExportVDF.
  2. Specify a DB_NAME_SLUG for the class
  3. The class should implement:
    1. make_parser() function to add database specific arguments to the export_vdf CLI
    2. export_vdb() function to prompt user for info not provided in the CLI. It should then call the get_data() function.
    3. get_data() function to download points (in a batched manner) with all the metadata from the specified index of the vector database. This data should be stored in a series of parquet files/folders. The metadata should be stored in a json file with the schema above.
  4. Use the script to export data from an example index of the vector database and verify that the data is exported correctly.

Import:

  1. In your import file, define a class ImportABC which inherits from ImportVDF.
  2. Specify a DB_NAME_SLUG for the class
  3. The class should implement:
    1. make_parser() function to add database specific arguments to the import_vdf CLI, such as the url of the database, any authentication tokens, etc.
    2. import_vdb() function to prompt user for info not provided in the CLI. It should then call the upsert_data() function.
    3. upsert_data() function to upload points from a vdf dataset (in a batched manner) with all the metadata to the specified index of the vector database. All metadata about the dataset should be read from the VDF_META.json file in the vdf folder.
  4. Use the script to import data from the example vdf dataset exported in the previous step and verify that the data is imported correctly.

Changing the VDF specification

If you wish to change the VDF specification, please open an issue to discuss the change before sending a PR.

Efficiency improvements

If you wish to improve the efficiency of the import/export scripts, please fork the repo and send a PR.

Telemetry

Running the scripts in the repo will send anonymous usage data to AI Northstar Tech to help improve the library.

You can opt out this by setting the environment variable DISABLE_TELEMETRY_VECTORIO to 1.

Questions

If you have any questions, please open an issue on the repo or message Dhruv Anand on LinkedIn

Contributors

Dhruv Anand
Dhruv Anand

💻 🐛 📖
Jayesh Rathi
Jayesh Rathi

💻
Jordan Totten
Jordan Totten

💻

评论

暂无评论