> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/pattern-custom-embedding-pipeline.md).

# 패턴: 사용자 지정 임베딩 파이프라인

Python SDK로 라이브러리 이미지를 자체 모델로 임베딩하고 벡터를 저장한 뒤, 유사한 프레임을 찾아 다음 라벨링 대상 데이터셋으로 만드는 패턴을 설명합니다.

부품 낙하처럼 알려진 실패 사례와 비슷해 보이는 프레임을 찾아 라벨링으로 보냅니다.

```python
from unitlab import UnitlabClient

client = UnitlabClient()
space = client.embedding_spaces.create("clip-vit-b32", dimensions=512, model_name="openai/clip-vit-base-patch32")

folder = client.assets.folder("FOLDER_ID")
assets = folder.list_items()

batch = []
for asset in assets:
    batch.append({"asset_id": asset.id, "vector": embed(asset)})   # your model
    if len(batch) == 1000:
        space.upsert_many(batch)
        batch = []
if batch:
    space.upsert_many(batch)

hits = space.search(embed_image("dropped_part.jpg"), limit=50)
similar = [hit["asset_id"] for hit in hits["results"] if hit["score"] > 0.85]

dataset = client.datasets.create("Dropped parts - candidates", asset_ids=similar)
client.close()
```

`embed()`는 사용자의 모델 코드를 나타냅니다. Unitlab은 벡터를 저장하고 검색할 뿐, 벡터를 계산하지는 않습니다.

| 팁                    | 이유                       |
| -------------------- | ------------------------ |
| 모델과 버전마다 공간 하나       | 서로 다른 모델의 벡터는 비교할 수 없습니다 |
| 1,000개 단위로 업서트       | 호출당 최대치입니다               |
| 비디오는 `level="frame"` | 파일이 아닌 프레임당 결과 1개        |
| HTTP 409에서 재시도       | 인덱스가 아직 구축 중입니다          |

## 관련 문서 <a href="#related" id="related"></a>

[임베딩 공간](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/embedding-spaces.md) · [벡터 업서트와 검색](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/upsert-and-search-vectors.md) · [데이터셋](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/datasets.md)
