Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain Chroma Similarity Search

From Leeroopedia
Knowledge Sources
Domains Vector_Search, Information_Retrieval
Last Updated 2026-02-11 00:00 GMT

Overview

Concrete tool for performing similarity search against a Chroma vector store provided by the LangChain Chroma integration.

Description

The Chroma.similarity_search() method embeds the query using the configured embedding model, then queries the Chroma collection for the k nearest documents. It supports metadata filtering via the filter parameter.

Usage

Call similarity_search() with a natural language query to retrieve relevant documents.

Code Reference

Source Location

  • Repository: langchain
  • File: libs/partners/chroma/langchain_chroma/vectorstores.py
  • Lines: L730-754

Signature

def similarity_search(
    self,
    query: str,
    k: int = DEFAULT_K,
    filter: dict[str, str] | None = None,
    **kwargs: Any,
) -> list[Document]:

Import

from langchain_chroma import Chroma

I/O Contract

Inputs

Name Type Required Description
query str Yes Natural language search query
k int No (default: 4) Number of results to return
filter dict or None No Metadata filter for narrowing results

Outputs

Name Type Description
return list[Document] Top-k most similar documents ordered by relevance

Usage Examples

Basic Search

results = vectorstore.similarity_search("What is LangChain?", k=3)
for doc in results:
    print(doc.page_content[:100])
    print(doc.metadata)

Filtered Search

results = vectorstore.similarity_search(
    "deployment strategies",
    k=5,
    filter={"source": "production_docs"},
)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment