liveBook · Manning

Chroma DB

As explained in Generative AI in Action

Chroma is an open-source vector database for storing and querying embeddings and their associated documents or metadata.

Chroma is a vector database used to store document text and its embeddings. In a PDF question-answering application, those stored embeddings help find pages semantically relevant to a user’s query. section 10.3.3

A Semantic Kernel workflow uses Chroma in three steps:

  • Extract text from PDF pages and generate embeddings with an Azure OpenAI embedding service. section 10.3.3
  • Attach Chroma through ChromaMemoryStore and choose a local persistence directory. section 10.3.3
  • Save nonempty page text with memory.save_information(), then query the stored information for relevant documents. section 10.3.3

For this Semantic Kernel example, pin chromadb to 0.4.15: versions 0.4.16 and higher are reported as incompatible. Treat that pin as an integration constraint, not a general recommendation for every Chroma deployment. section 10.3.3

Listing 10.3 Q&A over my PDFs: SK using Chroma
async def main():
    # Setup Semantic Kernel
    kernel = sk.Kernel()
    kernel.add_service(AzureChatCompletion(
            service_id="chat_completion",
            deployment_name=AOAI_MODEL,
            endpoint=AOAI_ENDPOINT,
            api_key=AOAI_KEY,
            api_version=API_VERSION))

    kernel.add_service(AzureTextEmbedding(
            service_id="text_embedding",
            deployment_name=AOAI_EMBEDDINGS,
            endpoint=AOAI_ENDPOINT,
            api_key=AOAI_KEY))

    # Specify the type of memory to attach to SK. 
    # Here we will use Chroma as it is easy to run it locally
    # You can specify location of Chroma DB files.
    store = ChromaMemoryStore(persist_directory=PERSIST_DIR)
    memory = SemanticTextMemory(storage=store, 
    embeddings_generator = kernel.get_service("text_embedding"))
    kernel.add_plugin(TextMemoryPlugin(memory), "TextMemoryPluginACDB")

    await load_vector_db(memory, VECTOR_DB)

    while True:
        prompt = check_prompt(input('Ask a question against 
        the PDF (type "quit" to exit):'))

        # Query the memory for most relevant match using
        # search_async specifying relevance score and 
        # "limit" of number of closest documents
        result = await memory.search(collection=VECTOR_DB, 
        limit=3, min_relevance_score=0.7, query=prompt)
        if result:
            print(result[0].text)
        else:
            print("No matches found.")

        print("-" * 80)


if __name__ == "__main__":
    asyncio.run(main())

The listing shows how a local ChromaMemoryStore is connected to SemanticTextMemory and an embedding service. section 10.3.3

How Generative AI in Action covers it

How deep it goes
Shows configuration, saving, and retrieval workflow without explaining Chroma’s internal indexing.
Examples
Uses a PDF question-answering application with Azure OpenAI embeddings and a locally persisted Chroma store.
What it assumes
Assumes basic Python application setup while defining embeddings as numerical representations of text meaning.
What you can do after
Apply it via Semantic Kernel to persist PDF text and embeddings for relevance queries.
How it connects
Connects vector databases to Semantic Kernel memory, embeddings, semantic similarity, and PDF question answering.

Also explained in

Compare how 7 books explain Chroma DB →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.