similarity_search_by_image() — langchain Function Reference
Architecture documentation for the similarity_search_by_image() function in vectorstores.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c0b7a4cd_c01b_9d43_bd62_7b531e7e6b42["similarity_search_by_image()"] d25f9e94_3ec0_b9ca_7d2f_eb7ef487ccab["Chroma"] c0b7a4cd_c01b_9d43_bd62_7b531e7e6b42 -->|defined in| d25f9e94_3ec0_b9ca_7d2f_eb7ef487ccab 76615968_7cd6_d5f7_a619_c032edfc26cb["similarity_search_by_vector()"] c0b7a4cd_c01b_9d43_bd62_7b531e7e6b42 -->|calls| 76615968_7cd6_d5f7_a619_c032edfc26cb style c0b7a4cd_c01b_9d43_bd62_7b531e7e6b42 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/chroma/langchain_chroma/vectorstores.py lines 945–984
def similarity_search_by_image(
self,
uri: str,
k: int = DEFAULT_K,
filter: dict[str, str] | None = None, # noqa: A002
**kwargs: Any,
) -> list[Document]:
"""Search for similar images based on the given image URI.
Args:
uri: URI of the image to search for.
k: Number of results to return.
filter: Filter by metadata.
**kwargs: Additional arguments to pass to function.
Returns:
List of Images most similar to the provided image. Each element in list is a
LangChain Document Object. The page content is b64 encoded image, metadata
is default or as defined by user.
Raises:
ValueError: If the embedding function does not support image embeddings.
"""
if self._embedding_function is not None and hasattr(
self._embedding_function, "embed_image"
):
# Obtain image embedding
# Assuming embed_image returns a single embedding
image_embedding = self._embedding_function.embed_image(uris=[uri])[0]
# Perform similarity search based on the obtained embedding
return self.similarity_search_by_vector(
embedding=image_embedding,
k=k,
filter=filter,
**kwargs,
)
msg = "The embedding function must support image embedding."
raise ValueError(msg)
Domain
Subdomains
Source
Frequently Asked Questions
What does similarity_search_by_image() do?
similarity_search_by_image() is a function in the langchain codebase, defined in libs/partners/chroma/langchain_chroma/vectorstores.py.
Where is similarity_search_by_image() defined?
similarity_search_by_image() is defined in libs/partners/chroma/langchain_chroma/vectorstores.py at line 945.
What does similarity_search_by_image() call?
similarity_search_by_image() calls 1 function(s): similarity_search_by_vector.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free