Returning all documents in MongoDB Atlas Vector Search

I have created an MongoDB atlas vector index LocationSemanticSearch based on location.

my api file

import base64

# import io
import os

from flask import Blueprint, jsonify, request

# from PIL import Image
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi

import hf
from model import Property, User

server_bp = Blueprint("server", __name__)
password = os.environ.get("MONGODB_PWD")
uri = f"mongodb+srv://hacker:{password}@cluster0.akxrbxh.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
client = MongoClient(uri, server_api=ServerApi('1'))
db = client['Apnahood']
users_collection = db['users']
house_collection = db['houses']


@server_bp.route('/register', methods=['POST'])
def register_user():
    data = request.get_json()
    username = data['username']
    password = data.get('password')
    email = data.get('email')

    cipher_text = hash(password)

    if not username or not password or not email:
        return jsonify({'error': 'Full credentials not given!'}), 400

    if users_collection.find_one({'username': username}):
        return jsonify({'error': 'Username already exists'}), 409

    if users_collection.find_one({'email': email}):
        return jsonify({'error': 'Email already exists'}), 409

    try:
        user = User(username, cipher_text, email)
        users_collection.insert_one(user.to_dict())
        return jsonify({'message': 'User registered successfully'}), 200
    except Exception as e:
        return jsonify({'error': str(e)}), 500


@server_bp.route('/login', methods=['POST'])
def login_user():
    data = request.get_json()
    username = data.get('username')
    password = data.get('password')
    cipher_text = hash(password)

    if not username or not password:
        return jsonify({'error': 'Username and password are required'}), 400

    user = users_collection.find_one({'username': username})
    if not user:
        return jsonify({'error': 'User not found!'}), 404
    elif user['password'] == cipher_text:
        return jsonify({'message': 'Login successful'}), 200
    else:
        return jsonify({'error': 'Invalid username or password'}), 401


@server_bp.route('/add-property', methods=['POST'])
def setProperties():
    try:
        data = request.form.to_dict()
        if house_collection.find_one({"name": data['name']}):
            return jsonify({'error': 'Property already exists!'}), 409

        image = request.files.get('image')
        if not image:
            return jsonify({'error': 'Image file is required'}), 400

        image_data = image.read()
        encoded_image = base64.b64encode(image_data).decode('utf-8')

        property = Property(name=data.get('name'),
                            owner=data.get('owner'),
                            rating=int(data['rating']),
                            cost=float(data['cost']),
                            address=data.get('address'),
                            thumbnail=encoded_image)

        property_dict = property.to_dict()

        result = house_collection.insert_one(property_dict)
        ref = result.inserted_id

        pipeline = [{
            '$match': {
                'username': data['owner']
            }
        }, {
            '$set': {
                'properties': {
                    '$concatArrays': ['$properties', [ref]]
                },
                'islandlord': True
            }
        }, {
            '$merge': {
                'into': 'users',
                'on': '_id',
                'whenMatched': 'merge',
                'whenNotMatched': 'fail'
            }
        }]

        users_collection.aggregate(pipeline)
        return jsonify({'objectId': str(ref)}), 201

    except Exception as e:
        return jsonify({"error": str(e)}), 500


@server_bp.route('/get-properties', methods=['POST'])
def getProperties():
    data = request.get_json()
    q = data.get('query')

    if not q:
        return jsonify({'error': 'Location parameter is required'}), 400

    try:
        properties = house_collection.aggregate([{
            "$vectorSearch": {
                "queryVector": hf.generate_embedding(q),
                "path": "addr_embedding_hf",
                "limit": 8,
                "index": "LocationSemanticSearch",
                "numCandidates": 300,
            }
        }])
        properties_list = []
        for i, property in enumerate(properties):
            del property["_id"]
            del property["addr_embedding_hf"]
            '''testing purpose'''
            # if 'thumbnail' in property:
            #     image_data = property['thumbnail']
            #     image_stream = io.BytesIO(base64.b64decode(image_data))
            #     image = Image.open(image_stream)
            #     if image.mode != 'RGB':
            #         image = image.convert('RGB')
            #     image.save(f'output{i}.jpg')

            properties_list.append(property)
        return jsonify(properties_list), 200

    except Exception as e:
        return jsonify({"error": str(e)}), 500

searchindex jsonschema

{
  "fields": [
    {
      "numDimensions": 384,
      "path": "addr_embedding_hf",
      "similarity": "euclidean",
      "type": "vector"
    }
  ]
}

But upon querying, it is returning all documnets in my collection instead of filtered ones…

How to resolve this issue?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật