@Override
	protected int queryNearestVector(List<VectorResult> resultset, LSHVector vec, double simthresh,
			double sigthresh, int max) throws SQLException {
		PreparedStatement s =
			selectNearestVectorStatement.prepareIfNeeded(() -> initConnection().prepareStatement(
				"WITH const(cvec) AS (VALUES( lshvector_in( CAST( ? AS cstring) ) ) )," +
					" comp AS (" +
					" SELECT id,count,cvec,vec,lshvector_compare(cvec,vec) AS cfunc FROM const,vectable" +
					"        WHERE cvec % vec)" +
					" SELECT id,count,(comp.cfunc).sim,(comp.cfunc).sig,vec FROM comp" +
					" WHERE (comp.cfunc).sim > ? AND (comp.cfunc).sig > ?" +
					" ORDER BY (comp.cfunc).sim DESC" + " LIMIT ?"));
		s.setString(1, vec.saveSQL());
		s.setDouble(2, simthresh);
		s.setDouble(3, sigthresh);
		s.setInt(4, max);

		int total = 0;
		try (ResultSet rs = s.executeQuery()) {
			while (rs.next()) {
				VectorResult curres = new VectorResult();
				resultset.add(curres);
				curres.vectorid = rs.getLong(1);
				curres.hitcount = rs.getInt(2);
				curres.sim = rs.getDouble(3);
				curres.signif = rs.getDouble(4);
				final String vecstring = rs.getString(5);
				try {
					curres.vec = vectorFactory.restoreVectorFromSql(vecstring);
				}
				catch (final IOException e) {
					throw new SQLException(e.getMessage());
				}
				total += curres.hitcount;
			}
			return total;
		}
	}
@param resultset the list of result set objects to populate
@param vec the vector containing the saveSQL query statement
@param simthresh the similarity threshold
@param sigthresh the confidence threshold
@param max the max number of results to return
@return the number of results returned
@throws SQLException if there is a problem creating or executing the query
Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/client/PostgresFunctionDatabase.java