adachsoft / project-search-lib
Project metadata enrichment and cross-project search (metadata, semantic, hybrid).
Requires
- php: ^8.3
- adachsoft/collection: ^3.0
- adachsoft/embedding-contracts: ^0.1
- adachsoft/project-config-lib: ^0.1.0
- adachsoft/text-search: ^0.2.0
- adachsoft/vector-store-contracts: ^0.3.0
Requires (Dev)
- adachsoft/php-code-style: ^0.8.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.5
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Project metadata enrichment and cross-project search (metadata, semantic, hybrid) for PHP.
Purpose
adachsoft/project-search-lib exposes a single, framework agnostic entry point for working with a
catalog of projects described by adachsoft/project-config-lib:
- it enriches project definitions (title, description, keywords) with metadata discovered in
local project manifests such as
composer.json,package.jsonandREADME.md, - it builds a searchable projection of every configured project,
- it searches across all configured projects using metadata matching, semantic (embedding) matching or a hybrid of both.
The library does not ship storage, HTTP clients or embedding providers. Those concerns are
implemented behind the interfaces of adachsoft/project-config-lib,
adachsoft/embedding-contracts and adachsoft/vector-store-contracts, so the same facade works
with files, databases, local models or remote APIs.
Features
- Metadata search – weighted phrase matching over project id, title, description and keywords
built on
adachsoft/text-search(exact match first, similarity match as fallback). - Semantic search – vector similarity search over project documents embedded by any
EmbedderInterfaceimplementation and stored in anyVectorStoreInterfaceimplementation. - Hybrid search – weighted combination of metadata and semantic results with a single ranked hit list.
- Project enrichment – fills in weak or missing descriptions and keywords from project
manifests, with
forceanddryRunmodes and a per-change report. - Semantic index management – collection creation, incremental upsert based on document
hashes, orphan removal, and a status snapshot (
stale,missing,orphanedcounters). - Deterministic, immutable results – DTOs, value objects and typed collections for every request and response.
- Validation at the boundary – query length, result limit, index configuration and collection names are validated with clear library exceptions.
Requirements
- PHP 8.3 or newer
- A
ProjectConfigRepositoryInterfaceimplementation fromadachsoft/project-config-lib - For semantic and hybrid search: an
EmbedderInterfaceimplementation fromadachsoft/embedding-contractsand aVectorStoreInterfaceimplementation fromadachsoft/vector-store-contracts
Installation
composer require adachsoft/project-search-lib
Integration
ProjectSearchFactory builds a ready to use ProjectSearchFacadeInterface. The facade is the only
type you need to inject into your own code.
Metadata search only
<?php
declare(strict_types=1);
use AdachSoft\ProjectConfigLib\ProjectConfigRepositoryInterface;
use AdachSoft\ProjectSearchLib\Enum\SearchStrategyNameEnum;
use AdachSoft\ProjectSearchLib\ProjectSearchFactory;
use AdachSoft\ProjectSearchLib\Vo\SearchQueryVo;
/** @var ProjectConfigRepositoryInterface $projectConfigRepository */
$projectSearchFactory = new ProjectSearchFactory();
$projectSearchFacade = $projectSearchFactory->createMetadataOnly($projectConfigRepository);
$hits = $projectSearchFacade->search(
new SearchQueryVo('http client'),
SearchStrategyNameEnum::METADATA,
10,
);
foreach ($hits as $hit) {
printf("%s (%.2f) [%s]\n", $hit->title, $hit->score, implode(', ', $hit->matchedIn));
}
Metadata, semantic and hybrid search
<?php
declare(strict_types=1);
use AdachSoft\EmbeddingContracts\Contract\EmbedderInterface;
use AdachSoft\ProjectConfigLib\ProjectConfigRepositoryInterface;
use AdachSoft\ProjectSearchLib\Dto\SemanticIndexConfigDto;
use AdachSoft\ProjectSearchLib\ProjectSearchFactory;
use AdachSoft\VectorStoreContracts\Contract\VectorStoreInterface;
use AdachSoft\VectorStoreContracts\Enum\DistanceMetricEnum;
/** @var ProjectConfigRepositoryInterface $projectConfigRepository */
/** @var EmbedderInterface $embedder */
/** @var VectorStoreInterface $vectorStore */
$semanticIndexConfig = new SemanticIndexConfigDto(
collectionName: 'project_search',
embeddingModel: 'text-embedding-3-small',
embeddingDimensions: 1536,
distanceMetric: DistanceMetricEnum::COSINE,
minScore: 0.2,
);
$projectSearchFactory = new ProjectSearchFactory();
$projectSearchFacade = $projectSearchFactory->createWithSemanticSearch(
$projectConfigRepository,
$embedder,
$vectorStore,
$semanticIndexConfig,
);
Semantic index lifecycle
<?php
// Build or refresh the vector index.
$buildResult = $projectSearchFacade->rebuildSemanticIndex(force: false);
printf("upserted=%d skipped=%d deleted=%d\n",
$buildResult->recordsUpserted,
$buildResult->recordsSkippedUpToDate,
$buildResult->recordsDeleted,
);
// Inspect the index before searching.
$status = $projectSearchFacade->getSemanticIndexStatus();
if ($status->stale) {
// Rebuild when projects were added, edited or removed since the last index run.
$projectSearchFacade->rebuildSemanticIndex(force: true);
}
With force: false only documents whose content hash changed are embedded again; with
force: true every document is re-embedded. Records of projects that no longer exist are deleted in
both modes.
Enrichment
ProjectEnricher reads the base_path parameter of each project definition and inspects the
manifest found there. Projects without a valid base_path, without a supported manifest or without
useful metadata are reported in the result counters instead of raising an error.
<?php
// Report only, do not touch the repository.
$preview = $projectSearchFacade->enrich(force: false, dryRun: true);
foreach ($preview->changes as $change) {
printf("%s <- %s\n", $change->projectId, $change->sourceLabel);
}
// Apply the changes.
$result = $projectSearchFacade->enrich(force: false, dryRun: false);
Modes:
force | dryRun | Behaviour |
|---|---|---|
false | true/false | Fills description only when it is considered poor, and keywords only when empty. |
true | true/false | Replaces description and keywords with the manifest values. |
Result limits and errors
search() accepts a limit between 1 and 25. Semantic and hybrid strategies are only available
when the facade was created with an embedder and a vector store; otherwise
SemanticSearchUnavailableException is thrown. All library exceptions extend
AdachSoft\ProjectSearchLib\Exception\ProjectSearchException.
Examples
Runnable, step by step examples live in docs/examples:
Development
composer install
vendor/bin/phpunit --configuration phpunit.xml
vendor/bin/phpstan analyse
vendor/bin/rector
vendor/bin/php-cs-fixer fix
License
MIT. See the license field of composer.json.