主页

索引

模块索引

搜索页面

9.5. Chroma

  • Chroma(Chroma is the open-source embedding database. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs):

  • 官网: https://docs.trychroma.com/

  • quickstart:

    # 1. Install
    pip install chromadb
    
    # 2. Get the Chroma Client
    import chromadb
    chroma_client = chromadb.Client()
    
    # 3. Create a collection
    collection = chroma_client.create_collection(name="my_collection")
    
    # 4. Add some text documents to the collection
    collection.add(
        documents=["This is a document", "This is another document"],
        metadatas=[{"source": "my_source"}, {"source": "my_source"}],
        ids=["id1", "id2"]
    )
    # or
    collection.add(
        embeddings=[[1.2, 2.3, 4.5], [6.7, 8.2, 9.2]],
        documents=["This is a document", "This is another document"],
        metadatas=[{"source": "my_source"}, {"source": "my_source"}],
        ids=["id1", "id2"]
    )
    
    # 5. Query the collection
    results = collection.query(
        query_texts=["This is a query document"],
        n_results=2
    )
    

主页

索引

模块索引

搜索页面