MongoDBAtlasVectorSearch + Langchain + CSFLE

Hello, we are using the following method to search for text based on the embeddings. All works fine, but my question is how are things when having Client-Side Field Level Encryption?

I have just implemented CSFLE encryption on the “text” and “embedding” fields but search is not finding anything… Is this supported or shall I swap CSFLE with Queryable Encryption?

    db_collection = get_database_vectorstore()
    db = get_database()

    vector_search = MongoDBAtlasVectorSearch.from_connection_string(
        DB_CONNECTION_STRING, + "." +,
        # TODO: add user specific api key

    retriever = vector_search.as_retriever(
            "k": 20, #k closest matching documents
            "post_filter_pipeline": [
                {"$limit": 20}, 
                # sort by score in descending order
                {"$sort": {"score": -1}},
                # only show results for current user
                # TODO: limit initial search space to current user
                {"$match": {"user_id": userID}},
                # do not show these fields in the result
                {"$project": {"embedding": 0, "_id": 0}}],

Document in collection looks as follows:


Hey @Ivan_Tokev,

Welcome to the MongoDB Community forums!

As per the documentation, you can’t query CSFLE encrypted data using Atlas Search. For more info, please refer to the FAQ: Atlas Search.

Yes, you can use Queryable Encryption. Please note Queryable Encryption with equality queries is generally available (GA) in MongoDB 7.0 and later. However, please note that as per the documentation linked above Queryable Encryption is also incompatible with Atlas Search.

Best regards,

Hi @Kushagra_Kesav,

Thank you for the response!

I was hoping that I have mistake in the code and not unsupported scenario :frowning:
By any chance, is there any info if that will be supported/compatible in future?

Ivan Tokev