if filter is not None:
                filter_clauses = []
                IN, NIN = "in", "nin"
                for key, value in filter.items():
                    if isinstance(value, dict):
                        value_case_insensitive = {
                            k.lower(): v for k, v in value.items()
                        }
                        if IN in map(str.lower, value):
                            filter_by_metadata = self.EmbeddingStore.cmetadata[
                                key
                            ].astext.in_(value_case_insensitive[IN])
                        elif NIN in map(str.lower, value):
                            filter_by_metadata = self.EmbeddingStore.cmetadata[
                                key
                            ].astext.not_in(value_case_insensitive[NIN])
                        else:
                            filter_by_metadata = None
                        if filter_by_metadata is not None:
                            filter_clauses.append(filter_by_metadata)
                    else:
                        filter_by_metadata = self.EmbeddingStore.cmetadata[
                            key
                        ].astext == str(value)
                        filter_clauses.append(filter_by_metadata)
                filter_by = sqlalchemy.and_(filter_by, *filter_clauses)
            _type = self.EmbeddingStore
            results: List[Any] = (
                session.query(
                    self.EmbeddingStore,
                    self.distance_strategy(embedding).label("distance"),  # type: ignore
                )
                .filter(filter_by)
                .order_by(sqlalchemy.asc("distance"))
                .join(
                    self.CollectionStore,
                    self.EmbeddingStore.collection_id == self.CollectionStore.uuid,
                )
                .limit(k)
                .all()
            )
        return results
[docs]    def similarity_search_by_vector(
        self,
        embedding: List[float],
        k: int = 4,
        filter: Optional[dict] = None,