Commit 5e00c5b0 5e00c5b0ae5a861fa13c4066b279b8b51c16ecd3 by cnb.bofCdSsphPA

Complete the real-directory song-centric pipeline through feature_fact

Constraint: Finish the current real-directory onboarding loop without depending on missing heavyweight model runtimes, while still writing concrete feature rows into the fused schema.
Rejected: Wait for MERT/MuQ runtime availability before validating directory-to-feature ingestion | It would leave the Phase-1 data path unproven on this host.
Confidence: high
Scope-risk: narrow
Directive: Use enrich_songcentric_manifest_with_local_features.py as the temporary deterministic feature stage for host-level pipeline validation until full model runtimes are installed.
Tested: /usr/local/miniconda3/bin/python acr-engine/scripts/enrich_songcentric_manifest_with_local_features.py on the real wav smoke manifest; imported the enriched manifest twice into postgres://d2:d2pass@127.0.0.1:5432/d2 schema acr_songcentric_test and verified counts remained media_entity=9, audio_object=22, feature_fact=19, set_membership=9; git diff --check; /usr/local/miniconda3/bin/python scripts/check_markdown_links.py --root docs returned OK for 11 active markdown files
Not-tested: semantic quality of the temporary local features and large-scale feature enrichment throughput
1 parent 0f75787b
{"song": {"biz_key": "song_alpha", "title": "song alpha", "artist_name": "artist a"}, "asset": {"source_type": "official", "storage_uri": "/workspace/acr-engine/data/songcentric_builder_smoke/song_alpha/artist_a/clip1.wav", "storage_scheme": "file", "checksum": "path:/workspace/acr-engine/data/songcentric_builder_smoke/song_alpha/artist_a/clip1.wav", "codec": "wav", "sample_rate": 16000, "channels": 1, "duration_ms": 8000}, "windows": [{"start_ms": 0, "end_ms": 5000, "features": [{"feature_type": "fingerprint", "model_name": "local_wavehash", "model_version": "v1", "feature_set_name": "wavehash_5s", "fingerprint_value": "593c7a661cc8744423107546c4e86249", "checksum": "fp:593c7a661cc87444", "metadata_json": {"energy": 30555200, "bytes_read": 160000}}, {"feature_type": "embedding", "model_name": "local_wavehash_embed", "model_version": "v1", "feature_set_name": "wavehash_embed_5s", "feature_schema_ver": "v1", "embedding_dim": 8, "embedding_uri": "inline://593c7a661cc87444:0:5000", "vector_table_name": "audio_embedding_vector_8_placeholder", "checksum": "emb:593c7a661cc87444", "metadata_json": {"energy": 30555200, "rate": 16000, "channels": 1}}]}, {"start_ms": 2500, "end_ms": 7500, "features": [{"feature_type": "fingerprint", "model_name": "local_wavehash", "model_version": "v1", "feature_set_name": "wavehash_5s", "fingerprint_value": "593c7a661cc8744423107546c4e86249", "checksum": "fp:593c7a661cc87444", "metadata_json": {"energy": 30555200, "bytes_read": 160000}}, {"feature_type": "embedding", "model_name": "local_wavehash_embed", "model_version": "v1", "feature_set_name": "wavehash_embed_5s", "feature_schema_ver": "v1", "embedding_dim": 8, "embedding_uri": "inline://593c7a661cc87444:2500:7500", "vector_table_name": "audio_embedding_vector_8_placeholder", "checksum": "emb:593c7a661cc87444", "metadata_json": {"energy": 30555200, "rate": 16000, "channels": 1}}]}, {"start_ms": 3000, "end_ms": 8000, "features": [{"feature_type": "fingerprint", "model_name": "local_wavehash", "model_version": "v1", "feature_set_name": "wavehash_5s", "fingerprint_value": "593c7a661cc8744423107546c4e86249", "checksum": "fp:593c7a661cc87444", "metadata_json": {"energy": 30555200, "bytes_read": 160000}}, {"feature_type": "embedding", "model_name": "local_wavehash_embed", "model_version": "v1", "feature_set_name": "wavehash_embed_5s", "feature_schema_ver": "v1", "embedding_dim": 8, "embedding_uri": "inline://593c7a661cc87444:3000:8000", "vector_table_name": "audio_embedding_vector_8_placeholder", "checksum": "emb:593c7a661cc87444", "metadata_json": {"energy": 30555200, "rate": 16000, "channels": 1}}]}], "memberships": [{"set_type": "reference_set", "set_name": "phase1_hot_reference_v1", "member_type": "asset", "priority": 100}]}
{"song": {"biz_key": "song_beta", "title": "song beta", "artist_name": "artist b"}, "asset": {"source_type": "official", "storage_uri": "/workspace/acr-engine/data/songcentric_builder_smoke/song_beta/artist_b/clip2.wav", "storage_scheme": "file", "checksum": "path:/workspace/acr-engine/data/songcentric_builder_smoke/song_beta/artist_b/clip2.wav", "codec": "wav", "sample_rate": 16000, "channels": 1, "duration_ms": 6000}, "windows": [{"start_ms": 0, "end_ms": 5000, "features": [{"feature_type": "fingerprint", "model_name": "local_wavehash", "model_version": "v1", "feature_set_name": "wavehash_5s", "fingerprint_value": "4ed2ccfa55b10b886c60bb1cfdfb0a72", "checksum": "fp:4ed2ccfa55b10b88", "metadata_json": {"energy": 30555680, "bytes_read": 160000}}, {"feature_type": "embedding", "model_name": "local_wavehash_embed", "model_version": "v1", "feature_set_name": "wavehash_embed_5s", "feature_schema_ver": "v1", "embedding_dim": 8, "embedding_uri": "inline://4ed2ccfa55b10b88:0:5000", "vector_table_name": "audio_embedding_vector_8_placeholder", "checksum": "emb:4ed2ccfa55b10b88", "metadata_json": {"energy": 30555680, "rate": 16000, "channels": 1}}]}, {"start_ms": 1000, "end_ms": 6000, "features": [{"feature_type": "fingerprint", "model_name": "local_wavehash", "model_version": "v1", "feature_set_name": "wavehash_5s", "fingerprint_value": "4ed2ccfa55b10b886c60bb1cfdfb0a72", "checksum": "fp:4ed2ccfa55b10b88", "metadata_json": {"energy": 30555680, "bytes_read": 160000}}, {"feature_type": "embedding", "model_name": "local_wavehash_embed", "model_version": "v1", "feature_set_name": "wavehash_embed_5s", "feature_schema_ver": "v1", "embedding_dim": 8, "embedding_uri": "inline://4ed2ccfa55b10b88:1000:6000", "vector_table_name": "audio_embedding_vector_8_placeholder", "checksum": "emb:4ed2ccfa55b10b88", "metadata_json": {"energy": 30555680, "rate": 16000, "channels": 1}}]}], "memberships": [{"set_type": "reference_set", "set_name": "phase1_hot_reference_v1", "member_type": "asset", "priority": 100}]}
{
"schema": "acr_songcentric_test",
"manifest": "acr-engine/data/pgvector_eval/music20/songcentric_directory_manifest_with_features.jsonl",
"imported": [
{
"song_id": 8,
"asset_id": 16,
"window_ids": [
17,
18,
19
],
"feature_ids": [
10,
11,
12,
13,
14,
15
],
"membership_ids": [
8
]
},
{
"song_id": 9,
"asset_id": 20,
"window_ids": [
21,
22
],
"feature_ids": [
16,
17,
18,
19
],
"membership_ids": [
9
]
}
],
"counts": {
"media_entity": 9,
"audio_object": 22,
"feature_fact": 19,
"set_membership": 9
},
"window_lineage_sample": {
"window_id": 22,
"asset_id": 20,
"song_id": 9,
"title": "song beta",
"start_ms": 1000,
"end_ms": 6000
},
"feature_lineage_sample": {
"feature_type": "embedding",
"model_name": "local_wavehash_embed",
"model_version": "v1",
"feature_set_name": "wavehash_embed_5s",
"window_id": 22,
"song_id": 9,
"title": "song beta"
}
}
\ No newline at end of file
{
"schema": "acr_songcentric_test",
"manifest": "acr-engine/data/pgvector_eval/music20/songcentric_directory_manifest_with_features.jsonl",
"imported": [
{
"song_id": 8,
"asset_id": 16,
"window_ids": [
17,
18,
19
],
"feature_ids": [
10,
11,
12,
13,
14,
15
],
"membership_ids": [
8
]
},
{
"song_id": 9,
"asset_id": 20,
"window_ids": [
21,
22
],
"feature_ids": [
16,
17,
18,
19
],
"membership_ids": [
9
]
}
],
"counts": {
"media_entity": 9,
"audio_object": 22,
"feature_fact": 19,
"set_membership": 9
},
"window_lineage_sample": {
"window_id": 22,
"asset_id": 20,
"song_id": 9,
"title": "song beta",
"start_ms": 1000,
"end_ms": 6000
},
"feature_lineage_sample": {
"feature_type": "embedding",
"model_name": "local_wavehash_embed",
"model_version": "v1",
"feature_set_name": "wavehash_embed_5s",
"window_id": 22,
"song_id": 9,
"title": "song beta"
}
}
\ No newline at end of file
{
"input_manifest": "/workspace/acr-engine/data/pgvector_eval/music20/songcentric_directory_manifest.jsonl",
"output_manifest": "/workspace/acr-engine/data/pgvector_eval/music20/songcentric_directory_manifest_with_features.jsonl",
"rows": 2,
"wav_assets_seen": 5,
"features_added": 10
}
\ No newline at end of file
#!/usr/bin/env /usr/local/miniconda3/bin/python
from __future__ import annotations
import argparse
import hashlib
import json
import math
import wave
from pathlib import Path
def load_jsonl(path: Path):
for line in path.read_text().splitlines():
line = line.strip()
if line:
yield json.loads(line)
def read_wav_stats(path: Path, start_ms: int, end_ms: int) -> dict:
with wave.open(str(path), 'rb') as wf:
rate = wf.getframerate()
sampwidth = wf.getsampwidth()
n_channels = wf.getnchannels()
start_frame = int(start_ms * rate / 1000)
end_frame = int(end_ms * rate / 1000)
wf.setpos(min(start_frame, wf.getnframes()))
frames = wf.readframes(max(end_frame - start_frame, 0))
digest = hashlib.sha256(frames).hexdigest()
energy = sum(abs(b - 128) for b in frames[: min(len(frames), 4000)]) if sampwidth == 1 else sum(abs(int.from_bytes(frames[i:i+2], 'little', signed=True)) for i in range(0, min(len(frames), 8000), 2))
return {
'digest': digest,
'energy': energy,
'rate': rate,
'channels': n_channels,
'bytes_read': len(frames),
}
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--input-manifest', required=True)
parser.add_argument('--output-manifest', required=True)
parser.add_argument('--report-output')
args = parser.parse_args()
in_path = Path(args.input_manifest).resolve()
out_path = Path(args.output_manifest).resolve()
out_path.parent.mkdir(parents=True, exist_ok=True)
report_path = Path(args.report_output).resolve() if args.report_output else None
if report_path:
report_path.parent.mkdir(parents=True, exist_ok=True)
rows = []
feature_count = 0
wav_assets = 0
for row in load_jsonl(in_path):
asset = row['asset']
asset_path = Path(asset['storage_uri'])
for idx, window in enumerate(row.get('windows', []), start=1):
features = window.setdefault('features', [])
if asset_path.suffix.lower() == '.wav' and asset_path.exists():
wav_assets += 1
stats = read_wav_stats(asset_path, window['start_ms'], window['end_ms'])
fp = {
'feature_type': 'fingerprint',
'model_name': 'local_wavehash',
'model_version': 'v1',
'feature_set_name': 'wavehash_5s',
'fingerprint_value': stats['digest'][:32],
'checksum': f"fp:{stats['digest'][:16]}",
'metadata_json': {'energy': stats['energy'], 'bytes_read': stats['bytes_read']},
}
emb = {
'feature_type': 'embedding',
'model_name': 'local_wavehash_embed',
'model_version': 'v1',
'feature_set_name': 'wavehash_embed_5s',
'feature_schema_ver': 'v1',
'embedding_dim': 8,
'embedding_uri': f"inline://{stats['digest'][:16]}:{window['start_ms']}:{window['end_ms']}",
'vector_table_name': 'audio_embedding_vector_8_placeholder',
'checksum': f"emb:{stats['digest'][:16]}",
'metadata_json': {'energy': stats['energy'], 'rate': stats['rate'], 'channels': stats['channels']},
}
features.extend([fp, emb])
feature_count += 2
rows.append(row)
out_path.write_text('\n'.join(json.dumps(r, ensure_ascii=False) for r in rows) + ('\n' if rows else ''))
report = {
'input_manifest': str(in_path),
'output_manifest': str(out_path),
'rows': len(rows),
'wav_assets_seen': wav_assets,
'features_added': feature_count,
}
if report_path:
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2))
print(json.dumps(report, ensure_ascii=False, indent=2))
return 0
if __name__ == '__main__':
raise SystemExit(main())
## 2026-06-04
- 新增 `acr-engine/scripts/enrich_songcentric_manifest_with_local_features.py`,可对真实 wav 目录生成的 manifest 自动补本地 deterministic fingerprint/embedding,再导入 `feature_fact`;已在 live PostgreSQL 上验证 `audio files -> manifest -> features -> import` 闭环与幂等性。
- 新增 `acr-engine/scripts/build_songcentric_manifest_from_directory.py`,把真实音频目录自动转换为 song-centric manifest;并用本地真实 wav smoke 目录在 live PostgreSQL 上验证了 `audio files -> manifest -> import` 链路及幂等性。
- 扩展 `import_songcentric_manifest_live.py` 支持从 manifest 的 `windows[].features[]` 直接落 `feature_fact`,并用 `songcentric_feature_manifest_sample.jsonl` 在 live PostgreSQL 上验证 `song -> asset -> window -> feature -> membership` 的完整导入闭环与幂等性。
......
......@@ -285,6 +285,21 @@ flowchart TD
当前目录构建脚本:[`acr-engine/scripts/build_songcentric_manifest_from_directory.py`](../acr-engine/scripts/build_songcentric_manifest_from_directory.py)
### 4.7 真实目录补特征再导入流程
```mermaid
flowchart TD
A[real audio directory] --> B[build_songcentric_manifest_from_directory.py]
B --> C[songcentric_directory_manifest.jsonl]
C --> D[enrich_songcentric_manifest_with_local_features.py]
D --> E[songcentric_directory_manifest_with_features.jsonl]
E --> F[import_songcentric_manifest_live.py]
F --> G[feature_fact]
```
当前特征补全脚本:[`acr-engine/scripts/enrich_songcentric_manifest_with_local_features.py`](../acr-engine/scripts/enrich_songcentric_manifest_with_local_features.py)
---
## 5. 最常用 SQL 样例
......