定制 adachsoft/vector-store-contracts 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adachsoft/vector-store-contracts

Composer 安装命令:

composer require adachsoft/vector-store-contracts

包简介

Contracts and testing utilities for vector store implementations in PHP

README 文档

README

A PHP library providing comprehensive contracts and testing utilities for vector store implementations.

Overview

This package defines interfaces, DTOs, collections, and exceptions for vector stores, along with abstract PHPUnit contract tests that can be extended by concrete implementations. It provides a provider-agnostic foundation for integrating vector databases in PHP applications.

Installation

Install via Composer:

composer require adachsoft/vector-store-contracts

After installation you can immediately use the in-memory adapter provided by this package under the AdachSoft\\VectorStoreInMemory namespace. It is intended primarily for testing, examples and as a reference implementation of the contracts, not as a production-ready backend.

Contracts Overview

Core Interfaces

  • VectorStoreInterface - Main entrypoint for managing vector collections (namespaces)
  • VectorCollectionRepositoryInterface - CRUD and search operations on a single collection
  • VectorStoreFactoryInterface - Factory for creating configured vector store instances

Data Transfer Objects

  • VectorRecordDto - Record with vector embedding and metadata
  • SearchQueryDto - Vector search query with filters and constraints
  • SearchResultDto - Single search result with similarity score
  • UpsertResultDto - Result of insert/update operations

Collections

  • FloatVectorCollection - Immutable collection of float vectors
  • MetadataCollection - Immutable map of scalar metadata
  • FilterCollection - Immutable map of search filters
  • SearchResultDtoCollection - Immutable collection of search results

Supporting Types

  • DistanceMetricEnum - Supported distance metrics (COSINE, EUCLIDEAN, DOT_PRODUCT)
  • VectorStoreException - Base exception for the library
  • CollectionNotFoundException - Thrown when collection doesn't exist
  • UpsertFailedException - Thrown when insert/update fails
  • DimensionMismatchException - Thrown when vector dimensions don't match

Implementing a Provider

To integrate a concrete vector database (e.g., Qdrant, Milvus, PostgreSQL with pgvector, etc.):

  1. Create your own package that requires this contracts library.
  2. Implement the interfaces in your classes:
    • Create a concrete VectorStoreInterface implementation.
    • Create concrete VectorCollectionRepositoryInterface implementations.
    • Optionally create a VectorStoreFactoryInterface for configuration.
  3. Ensure your implementation satisfies all contract requirements and semantics (distance metrics, filters, exceptions).
  4. Use the provided DTOs and collections for data exchange.
  5. Use the in-memory implementation (AdachSoft\\VectorStoreInMemory) and .docs/implementation-guide.md as a reference for structure, behaviour and tests integration.

In-memory reference implementation

This package ships with a simple, fully in-memory implementation of the contracts under the AdachSoft\\VectorStoreInMemory namespace. It stores collections and records in PHP arrays and implements all behaviours required by the contract tests (distance metrics, filters, exceptions).

You can use it as:

  • a quick way to experiment with the contracts without configuring an external vector store,
  • a reference for how to implement VectorStoreInterface, VectorCollectionRepositoryInterface and VectorStoreFactoryInterface,
  • a baseline to run and understand the contract tests.

Key classes:

  • InMemoryVectorStore – manages collections and exposes repositories,
  • InMemoryVectorCollectionRepository – performs CRUD and vector search in memory,
  • InMemoryVectorStoreFactory – creates in-memory stores and can serve as a template for real factories.

See .docs/implementation-guide.md for a detailed walkthrough of these classes and their responsibilities.

Contract Tests

This package ships with abstract PHPUnit test cases for validating implementations:

  • AbstractVectorStoreContractTestCase - Tests VectorStoreInterface behavior
  • AbstractVectorCollectionRepositoryContractTestCase - Tests repository behavior

To use these tests in your implementation:

// In your test file
class MyVectorStoreTest extends AbstractVectorStoreContractTestCase
{
    protected function createStore(): VectorStoreInterface
    {
        return new MyVectorStoreImplementation();
    }
}

class MyVectorCollectionRepositoryTest extends AbstractVectorCollectionRepositoryContractTestCase
{
    protected function createRepository(): VectorCollectionRepositoryInterface
    {
        // Create and return your repository instance
        return new MyVectorCollectionRepository();
    }
}

Development

This project uses quality tools configured via Composer scripts:

# Check code style
composer cs:check

# Fix code style
composer cs:fix

# Run static analysis
composer stan

# Run Rector refactoring
composer rector

The repository includes ready-to-use configurations for:

  • PHP-CS-Fixer - Code style enforcement
  • PHPStan - Static analysis
  • Rector - Automated refactoring

Requirements

  • PHP >= 8.0
  • Composer

License

MIT

adachsoft/vector-store-contracts 适用场景与选型建议

adachsoft/vector-store-contracts 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「phpunit」 「contracts」 「embeddings」 「vector-database」 「semantic-search」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 adachsoft/vector-store-contracts 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adachsoft/vector-store-contracts 我们能提供哪些服务?
定制开发 / 二次开发

基于 adachsoft/vector-store-contracts 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 54
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-13