Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGwEI-0019wk-Kk for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Jun 2024 07:47:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sGwEH-003ftY-3s for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Jun 2024 07:47:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGwEG-003fsx-Le for pgsql-hackers@lists.postgresql.org; Tue, 11 Jun 2024 07:47:41 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGwEE-000lAe-5A for pgsql-hackers@postgresql.org; Tue, 11 Jun 2024 07:47:40 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4Vz13m4MXgzyT0; Tue, 11 Jun 2024 10:47:32 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1718092052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KAjtAcPHUSD5cHgJzVTii4DeBLgz01ktvlD4Ft2NvIY=; b=oh7M5106ZZo/Dfl+QqLNWmuISc8NNt5lTLUsiH9L1d2MhJB7oGeDhZn3IzThlRiEQnhzmR 5+I1Utn2/tIat+1hWBvmLdxuVH5WDlpADlJgahbU/9habsBUp+gouPbxFVRdZJno9ok14d rxeeMfnuH6+29cD/fhN2CVKEAU4+Cpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1718092052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KAjtAcPHUSD5cHgJzVTii4DeBLgz01ktvlD4Ft2NvIY=; b=cYeMHqEyuMLq8ZDhDsl3krUtkebRU53Ri5J2DIkGDHcIeexFD7TrhQsf+83G0zK4vLhbl+ pY31YC9/WdZlaK3O+ye/ZMvZpK+shOLQQhqfpyAfMtELT/UREiwNyO7bjZN0y1OL6dUDwP vxGwkEcrgwInJT8P8jsDE52OILBxdpQ= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1718092052; a=rsa-sha256; cv=none; b=iVN7eWmWJoFu5WCERzdLv/1goY+UvOQjI/nOj5rNGwR3YrKzpn4YfdgOLVkWIPp+yZC/j/ B8rm8Itn8VYApw4gOxj6wDEYAryImagGgkQ+zvcUDL94xxGJ5zKwzE8Z10NRWhotSujKiM uR0DbfMQQuegcuk6vI9rTa8ix9ur188= Message-ID: Date: Tue, 11 Jun 2024 10:47:31 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Trying out read streams in pgvector (an extension) To: Thomas Munro , pgsql-hackers References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/06/2024 07:53, Thomas Munro wrote: > Someone involved in that project mentioned that it's probably not a > great topic to research in practice, because real world users of HNSW > use fully cached ie prewarmed indexes, because the performance is so > bad otherwise. (Though maybe that argument is a little circular...). I think that's true in practice for *building* an HNSW index, but faster *searching* when the index is not in memory seems quite useful. And of course, faster is always better, even if it's only in a non-optimal scenario. > So although this patch clearly speeds up cold HSNW searches to a > degree controlled by effective_io_concurrency, I'll probably look for > something else. Suggestions for interesting index types to look at > streamifying are very welcome! GiST and GIN? > Hmm. If that's really true about HNSW though, then there may still be > an opportunity to do automatic memory prefetching[1]. But then in the > case of index building, "stream" is NULL in this patch anyway. It > surely must also be possible to find some good places to put > profitable explicit pg_mem_prefetch() calls given the predictability > and the need to get only ~60ns ahead for that usage. I didn't look > into that because I was trying to prove things about read_stream.c, > not get involved in another project :-D > > Here ends my science experiment report, which I'm dropping here just > in case others see useful ideas here. The main thing I learned about > the read stream API is that it'd be nice to be able to reset the > stream but preserve the distance (something that came up on the > streaming sequential scan thread for a different reason), to deal with > cases where look-ahead opportunities come in bursts but you want a > longer lived stream than I used here. That is the reason the patch > creates and destroys temporary streams in a loop; doh. It also > provides an interesting case study for what speculative random > look-ahead support might need to look like. This reminds me of a prototype I wrote earlier, see https://github.com/pgvector/pgvector/pull/386, 1st commit. It reorganizes HnswSearchLayer() so that it in iteration, it first collects all the neighbors to visit, and then visits them, somewhat similar to your patch. -- Heikki Linnakangas Neon (https://neon.tech)