diff --git a/src/hnsw.c b/src/hnsw.c
index 758e41842..c174da40e 100644
--- a/src/hnsw.c
+++ b/src/hnsw.c
@@ -14,6 +14,8 @@
 #endif
 
 int			hnsw_ef_search;
+bool		hnsw_enable_iterator;
+bool		hnsw_strict_order;
 static relopt_kind hnsw_relopt_kind;
 
 /*
@@ -39,6 +41,12 @@ HnswInit(void)
 	DefineCustomIntVariable("hnsw.ef_search", "Sets the size of the dynamic candidate list for search",
 							"Valid range is 1..1000.", &hnsw_ef_search,
 							HNSW_DEFAULT_EF_SEARCH, HNSW_MIN_EF_SEARCH, HNSW_MAX_EF_SEARCH, PGC_USERSET, 0, NULL, NULL, NULL);
+	DefineCustomBoolVariable("hnsw.enable_iterator", "Use iterator to support filtering",
+							 NULL, &hnsw_enable_iterator,
+							 true, PGC_USERSET, 0, NULL, NULL, NULL);
+	DefineCustomBoolVariable("hnsw.strict_order", "Provide string order of returned results in HNSW iterator",
+							 "Skip results with violates distance order", &hnsw_strict_order,
+							 false, PGC_USERSET, 0, NULL, NULL, NULL);
 }
 
 /*
diff --git a/src/hnsw.h b/src/hnsw.h
index cfba560b1..adc71e64d 100644
--- a/src/hnsw.h
+++ b/src/hnsw.h
@@ -88,6 +88,8 @@
 
 /* Variables */
 extern int	hnsw_ef_search;
+extern bool hnsw_enable_iterator;
+extern bool hnsw_strict_order;
 
 typedef struct HnswNeighborArray HnswNeighborArray;
 
@@ -215,13 +217,28 @@ typedef struct HnswNeighborTupleData
 
 typedef HnswNeighborTupleData * HnswNeighborTuple;
 
+typedef struct
+{
+	pairingheap *C;
+	pairingheap *W;
+	HTAB*        v;
+	int          n;
+} LayerScanDesc;
+
 typedef struct HnswScanOpaqueData
 {
 	bool		first;
 	List	   *w;
 	MemoryContext tmpCtx;
 
-	/* Support functions */
+	LayerScanDesc* layers;
+	int			n_layers;
+	int         m;
+	Datum       q;
+	float       last_distance;
+	HnswCandidate *hc;
+
+    /* Support functions */
 	FmgrInfo   *procinfo;
 	FmgrInfo   *normprocinfo;
 	Oid			collation;
@@ -285,6 +302,8 @@ void		HnswLoadElement(HnswElement element, float *distance, Datum *q, Relation i
 void		HnswSetElementTuple(HnswElementTuple etup, HnswElement element);
 void		HnswUpdateConnection(HnswElement element, HnswCandidate * hc, int m, int lc, int *updateIdx, Relation index, FmgrInfo *procinfo, Oid collation);
 void		HnswLoadNeighbors(HnswElement element, Relation index, int m);
+HnswCandidate* HnswGetNext(IndexScanDesc scan);
+void		HnswInitScan(IndexScanDesc scan, Datum q);
 
 /* Index access methods */
 IndexBuildResult *hnswbuild(Relation heap, Relation index, IndexInfo *indexInfo);
diff --git a/src/hnswscan.c b/src/hnswscan.c
index d391a10d7..240f96f9c 100644
--- a/src/hnswscan.c
+++ b/src/hnswscan.c
@@ -1,3 +1,4 @@
+#include <float.h>
 #include "postgres.h"
 
 #include "access/relscan.h"
@@ -7,36 +8,33 @@
 #include "storage/lmgr.h"
 #include "utils/memutils.h"
 
-/*
- * Algorithm 5 from paper
- */
 static List *
 GetScanItems(IndexScanDesc scan, Datum q)
 {
-	HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
-	Relation	index = scan->indexRelation;
-	FmgrInfo   *procinfo = so->procinfo;
-	Oid			collation = so->collation;
-	List	   *ep;
-	List	   *w;
-	int			m;
-	HnswElement entryPoint;
-
-	/* Get m and entry point */
-	HnswGetMetaPageInfo(index, &m, &entryPoint);
-
-	if (entryPoint == NULL)
-		return NIL;
-
-	ep = list_make1(HnswEntryCandidate(entryPoint, q, index, procinfo, collation, false));
-
-	for (int lc = entryPoint->level; lc >= 1; lc--)
-	{
-		w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, m, false, NULL);
-		ep = w;
-	}
-
-	return HnswSearchLayer(q, ep, hnsw_ef_search, 0, index, procinfo, collation, m, false, NULL);
+       HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
+       Relation        index = scan->indexRelation;
+       FmgrInfo   *procinfo = so->procinfo;
+       Oid                     collation = so->collation;
+       List       *ep;
+       List       *w;
+       int                     m;
+       HnswElement entryPoint;
+
+       /* Get m and entry point */
+       HnswGetMetaPageInfo(index, &m, &entryPoint);
+
+       if (entryPoint == NULL)
+               return NIL;
+
+       ep = list_make1(HnswEntryCandidate(entryPoint, q, index, procinfo, collation, false));
+
+       for (int lc = entryPoint->level; lc >= 1; lc--)
+       {
+               w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, m, false, NULL);
+               ep = w;
+       }
+
+       return HnswSearchLayer(q, ep, hnsw_ef_search, 0, index, procinfo, collation, m, false, NULL);
 }
 
 /*
@@ -142,6 +140,7 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
 {
 	HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
 	MemoryContext oldCtx = MemoryContextSwitchTo(so->tmpCtx);
+	HnswCandidate *hc;
 
 	/*
 	 * Index can be used to scan backward, but Postgres doesn't support
@@ -163,29 +162,50 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
 		/* Get scan value */
 		value = GetScanValue(scan);
 
-		/*
-		 * Get a shared lock. This allows vacuum to ensure no in-flight scans
-		 * before marking tuples as deleted.
-		 */
-		LockPage(scan->indexRelation, HNSW_SCAN_LOCK, ShareLock);
-
-		so->w = GetScanItems(scan, value);
-
-		/* Release shared lock */
-		UnlockPage(scan->indexRelation, HNSW_SCAN_LOCK, ShareLock);
+		if (hnsw_enable_iterator)
+			HnswInitScan(scan, value);
+		else
+			so->w = GetScanItems(scan, value);
 
+		so->last_distance = 0;
 		so->first = false;
 	}
 
-	while (list_length(so->w) > 0)
+	while (hnsw_enable_iterator || list_length(so->w) > 0)
 	{
-		HnswCandidate *hc = llast(so->w);
 		ItemPointer heaptid;
 
+		if (hnsw_enable_iterator)
+		{
+			hc = so->hc;
+			if (hc == NULL)
+			{
+				do
+				{
+					hc = HnswGetNext(scan);
+					if (hc == NULL)
+						break;
+				}
+				while (hnsw_strict_order && hc->distance < so->last_distance);
+
+				if (hc == NULL)
+					break;
+
+				so->last_distance = hc->distance;
+				so->hc = hc;
+			}
+		}
+		else
+		{
+			hc = llast(so->w);
+		}
 		/* Move to next element if no valid heap TIDs */
 		if (list_length(hc->element->heaptids) == 0)
 		{
-			so->w = list_delete_last(so->w);
+			if (hnsw_enable_iterator)
+				so->hc = NULL;
+			else
+				so->w = list_delete_last(so->w);
 			continue;
 		}
 
diff --git a/src/hnswutils.c b/src/hnswutils.c
index 72cf94ea2..4f8067ccf 100644
--- a/src/hnswutils.c
+++ b/src/hnswutils.c
@@ -2,6 +2,7 @@
 
 #include <math.h>
 
+#include "access/relscan.h"
 #include "hnsw.h"
 #include "storage/bufmgr.h"
 #include "vector.h"
@@ -564,6 +565,191 @@ AddToVisited(HTAB *v, HnswCandidate * hc, Relation index, bool *found)
 	}
 }
 
+
+static void
+AddCandidate(IndexScanDesc scan, int lc, HnswCandidate *hc)
+{
+	HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
+	LayerScanDesc* layer = &so->layers[lc];
+	bool		visited;
+	AddToVisited(layer->v, hc, scan->indexRelation, &visited);
+	if (!visited)
+	{
+		pairingheap_add(layer->C, &(CreatePairingHeapNode(hc)->ph_node));
+		pairingheap_add(layer->W, &(CreatePairingHeapNode(hc)->ph_node));
+		layer->n += lc != 0 || list_length(hc->element->heaptids) != 0;
+	}
+}
+
+void
+HnswInitScan(IndexScanDesc scan, Datum q)
+{
+	HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
+	HnswElement entryPoint;
+	Relation	index = scan->indexRelation;
+	int         i;
+	HASHCTL		hash_ctl;
+	HnswCandidate *hc;
+
+	/* Create hash table */
+	hash_ctl.hcxt = CurrentMemoryContext;
+	if (index == NULL)
+	{
+		hash_ctl.keysize = sizeof(HnswElement *);
+		hash_ctl.entrysize = sizeof(HnswElement *);
+	}
+	else
+	{
+		hash_ctl.keysize = sizeof(ItemPointerData);
+		hash_ctl.entrysize = sizeof(ItemPointerData);
+	}
+
+	so->hc = NULL;
+	so->q = q;
+
+	/* Get m and entry point */
+	HnswGetMetaPageInfo(index, &so->m, &entryPoint);
+	if (entryPoint == NULL)
+	{
+		so->n_layers = 0;
+		so->layers = NULL;
+		return;
+	}
+	hc = HnswEntryCandidate(entryPoint, q, index, so->procinfo, so->collation, false);
+	so->n_layers = entryPoint->level + 1;
+	so->layers = (LayerScanDesc*)palloc(sizeof(LayerScanDesc) * so->n_layers);
+	for (i = 0; i < so->n_layers; i++)
+	{
+		so->layers[i].C = pairingheap_allocate(CompareNearestCandidates, NULL);
+		so->layers[i].W = pairingheap_allocate(CompareNearestCandidates, NULL);
+		so->layers[i].v = hash_create("hnsw visited", 256, &hash_ctl, HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
+		so->layers[i].n = 0;
+	}
+	AddCandidate(scan, so->n_layers-1, hc);
+}
+
+static pairingheap_node *
+pairingheap_nth(pairingheap *heap, int nth)
+{
+	if (nth > 0) {
+		pairingheap_node* first = pairingheap_remove_first(heap);
+		pairingheap_node* result = pairingheap_nth(heap, nth-1);
+		pairingheap_add(heap, first);
+		return result;
+	}
+	else
+	{
+		return pairingheap_first(heap);
+	}
+}
+
+static bool
+MoreCandidates(IndexScanDesc scan, int lc, int ef)
+{
+	HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
+	Relation	index = scan->indexRelation;
+	LayerScanDesc* layer = &so->layers[lc];
+
+	while (!pairingheap_is_empty(layer->C))
+	{
+		HnswNeighborArray *neighborhood;
+		HnswCandidate *c = ((HnswPairingHeapNode *) pairingheap_first(layer->C))->inner;
+		if (layer->n >= ef && c->distance > ((HnswPairingHeapNode*) pairingheap_nth(layer->W, ef - 1))->inner->distance)
+			return true;
+
+		pairingheap_remove_first(layer->C);
+
+		if (c->element->neighbors == NULL)
+			HnswLoadNeighbors(c->element, index, so->m);
+
+		/* Get the neighborhood at layer lc */
+		neighborhood = &c->element->neighbors[lc];
+
+		for (int i = 0; i < neighborhood->length; i++)
+		{
+			HnswCandidate *e = &neighborhood->items[i];
+			bool		visited;
+
+
+			AddToVisited(layer->v, e, index, &visited);
+
+			if (!visited)
+			{
+				float		eDistance;
+				HnswCandidate *ec;
+
+				if (index == NULL)
+					eDistance = GetCandidateDistance(e, so->q, so->procinfo, so->collation);
+				else
+					HnswLoadElement(e->element, &eDistance, &so->q, index, so->procinfo, so->collation, false);
+
+				Assert(!e->element->deleted);
+
+				/* Make robust to issues */
+				if (e->element->level < lc)
+					continue;
+
+				/* Copy e */
+				ec = palloc(sizeof(HnswCandidate));
+
+				ec->element = e->element;
+				ec->distance = eDistance;
+
+				pairingheap_add(layer->C, &(CreatePairingHeapNode(ec)->ph_node));
+				pairingheap_add(layer->W, &(CreatePairingHeapNode(ec)->ph_node));
+				layer->n += lc != 0 || list_length(ec->element->heaptids) != 0;
+			}
+		}
+	}
+	return false;
+}
+
+static HnswCandidate*
+GetCandidate(IndexScanDesc scan, int lc, int ef)
+{
+	HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
+	LayerScanDesc* layer = &so->layers[lc];
+	while (true)
+	{
+		if (!MoreCandidates(scan, lc, ef))
+		{
+			if (lc+1 != so->n_layers)
+			{
+				HnswCandidate* hc = GetCandidate(scan, lc+1, 1);
+				if (hc != NULL)
+				{
+					AddCandidate(scan, lc, hc);
+					continue;
+				}
+			}
+			break;
+		}
+		else if (layer->n >= ef)
+		{
+			/* Collect enough results to return the best */
+			break;
+		}
+	}
+	if (pairingheap_is_empty(layer->W))
+	{
+		return NULL;
+	}
+	else
+	{
+		HnswCandidate* hc = ((HnswPairingHeapNode *) pairingheap_remove_first(layer->W))->inner;
+		layer->n -= lc != 0 || list_length(hc->element->heaptids) != 0;
+		return hc;
+	}
+}
+
+HnswCandidate*
+HnswGetNext(IndexScanDesc scan)
+{
+	HnswScanOpaque so = (HnswScanOpaque) scan->opaque;
+	return so->n_layers == 0 ? NULL : GetCandidate(scan, 0, hnsw_ef_search);
+}
+
+
 /*
  * Algorithm 2 from paper
  */
diff --git a/test/t/015_hnsw_duplicates.pl b/test/t/015_hnsw_duplicates.pl
index 7e11deed3..f9b142f92 100644
--- a/test/t/015_hnsw_duplicates.pl
+++ b/test/t/015_hnsw_duplicates.pl
@@ -28,7 +28,7 @@ sub test_duplicates
 		SET hnsw.ef_search = 1;
 		SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]') t;
 	));
-	is($res, 10);
+	is($res, 20);
 }
 
 # Test duplicates with build
