1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【個人開発】【ノート】ChromaDB のコレクションとは?

Posted at

はじめに

LangChain と ChromaDB を組み合わせたベクトルストア構築で、
vs_new._collection.id を使って古いフォルダを削除する場面があります。

current_uuid = vs_new._collection.id

ここで登場する ._collection は一体何を指しているのか?
本記事では ChromaDB の「コレクション」 という概念と、
vs_new._collection の正体・データ型・使いどころを解説します。


コレクション(Collection)とは?

  • コレクション は ChromaDB における「ベクトル+メタデータ」をまとめた 保存単位
  • 複数のドキュメント(テキストチャンク)を一つの コレクション に登録し、
    類似検索やフィルタリングを行う際の対象グループとなります

コレクションの役割

  1. データ登録(Insert)
  2. 類似検索(Query)
  3. メタデータ管理
  4. 永続化/読み込み

これらをまとめて扱うのが「コレクション」です。


vs_new._collection の正体

vs_new は LangChain のラッパーである以下のインスタンスです。

from langchain_community.vectorstores import Chroma

vs_new = Chroma.from_texts(
    texts=chunks,
    embedding=embeds,
    client_settings=CHROMA_SETTINGS,
)
  • ._collection は、その内部で実際の ChromaDB クライアントが保持する
    「コレクションオブジェクト」を参照する属性です
  • データ型は ChromaDB 本体の実装によりますが、Local モードでは例えば以下のようなクラスです:
>>> type(vs_new._collection)
<class 'chromadb.db.local.LocalCollection'>
  • このオブジェクトが保持する主な属性・メソッド:

    • id:UUID 形式の一意識別子
    • add() / get_nearest_neighbors() などの CRUD API
    • 永続化先パス(persist_directory/UUID)の管理

実際の利用例

# コレクションの登録ディレクトリ確認
collection = vs_new._collection
print("コレクションID:", collection.id)
# → vectorstore/<collection.id>/ 以下に SQLite/Parquet が保存される

# 類似検索はラッパー経由で実行
results = vs_new.similarity_search_with_score("検索クエリ", k=5)
  • UUID を使うことで、複数コレクションを同一ディレクトリ下に共存させたり、
    古いコレクションのみを削除したりする運用が可能になります。

まとめ

  • vs_new._collectionChromaDB が管理するコレクションオブジェクト
  • コレクションはベクトルとメタデータの「グループ」であり、
    登録・検索・永続化の単位となる
  • ._collection.id を活用して、UUIDごとにフォルダを管理・掃除するのがベストプラクティス
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?