NIP-91: AND operator for filters (Formerly NIP-119)#1365
NIP-91: AND operator for filters (Formerly NIP-119)#1365staab merged 7 commits intonostr-protocol:masterfrom
Conversation
|
Have you implemented a relay? I can't even make tag queries fast as they are. |
|
Not yet, no. But I've scraped, researched and monitored them for almost two years. There is a PR to
|
|
Satellite Node relay now supports AND tag filters satellite-earth/core@15b8132 |
|
I cannot think of a use case where I want to ask a relay for only events that have the same tag twice with two different values. |
|
@mikedilger @fiatjaf Really? I can think of an infinite number of cases. Here's one: To retrieve that combination in a populated dataset client-side could easily be <10% of the result provided by And another: easily |
|
I think this proposal is reasonable if we limit But even if it's reasonable I also think it's a slippery slope and soon people will be demanding full SQL support on relays. |
|
Postgres has a We have been able to work around Nostr filter limitations by changing the events themselves in many cases. I think the torrent category example (or Amazon product filtering as another hypothetical), is still basically unsolved, and we worked around that by simply not supporting the ability to do it. 😃 I'm not sure it's worth changing NIP-01 filters. I've been shoehorning any extra functionality I need into NIP-50 search extensions. |
Why not just leave it to the operator to decide? Maybe i run a relay that stores a unique event kind and I have optimized it to support up to 20 and filters. Why shouldn't I be able to allow a client to run
Possible, and fair point. However, as proposed it's an optimization that just so happens to be a feature. If data is provided to prove that there is optimization benefits for all parties (relays, clients, users) this would establish a baseline that could be used as a measure against filter creep.
As proposed it's additive and does not "change" NIP-01 filters. |
|
Can we consider this to be part of NIP-01? I really dislike having to check if each relay offers custom commands before even enabling the UI for the feature in the client. Maybe that's going to be normal in the future, but we should consider minimizing the array of optional base-level stuff available to clients. Or maybe we go all out with tons of customizations and make checks for custom filter features the norm and in that case, something like NIP-11 must be merged with NIP-01. |
|
How would current relay implementations signal supporting this if it becomes part of 01? I think making this a separate NIP is better, with NIP 11 signaling. Much like NIP 70, that feels pretty similar. And perhaps make NIP 11 required. |
It would just be required for all relays to implement it. There is no signaling needed. My issue is that we are starting to have all these additional base protocol features without having a good signaling mechanism that must be present and accurate in all relays (most NIP-11 documents do not reflect what is implemented in the relay, so NIP-11 is quite useless for now) |
|
My question was more about the transition period after merging. The current relay implementations wouldn't magically start supporting this (let alone running instances), you would need a mechanism to check for support. I agree the current state isn't great, but frankly that's always going to be a problem. You'll always have to code defensively and have fallbacks when a relay says one thing (or nothing), but behaves differently. |
|
Agree. We can have:
Today we have 1. If we think this PR is just for VERY RARE use cases where the client and the relay are probably coming from the same developer, then this makes sense. If we want to see more usage of this, then we have to go for 2 or 3. Since we like simplicity, 4 is not desired on Nostr. |
|
Feature support signaling is a hassle, but that's sort of the only downside. It would be nice to make any additions signal-able by putting them in a new NIP, so relays can signal support if they want to (even though many don't). |
|
The most important downside of feature signaling is that it makes changing things a much easier process than currently. |
But currently feature signaling is done by adding new NIPs, so.. I don't follow. Do you mean we should have a different way to signal feature support? |
|
FYI I have this implemented in netstr relay and deployed to a dev instance: |
|
What's worse than support signaling? A NIP that is merged too quickly and changes IMO Just leave this open and let relays signal support for it, like is already happening. If it works and is found helpful, the benefits of a merge will be implicit, the need for discussion will be reduced and the effort of merging will be minimized. I see no reason to rush this NIP (or really, most NIPs). |
|
I'm personally happy with this NIP and deployed it to production: https://relay.netstr.io/ |
|
I want to add a use-case for the possible use of this NIP. Is there any objection left here? When is it going to be merged? |
|
Instead of the special rules at the end about not mixing ANDs and ORs, this could have been specified in disjunctive normal form as an array of arrays, where the inner values are ANDed and then the array of those terms is ORed. Just a thought, not a push for a proposal or anything. |
|
Opened PR to nostr-tools for JavaScript nbd-wtf/nostr-tools#518 |
|
NIP-ND -> NIP-91 |
|
Built an example in applesauce for https://hzrd149.github.io/applesauce/examples/#hashtags/explore |
|
I just realized this is great for decrypted NIP-17 group chats where we need to filter by the presence of many p-tags in local dbs. @jb55 since you are putting them on nostrdb, have you thought about indexing in this way? |
|
Added to Amethyst/Quartz |
|
Next Nostr.land relay software release will support this |
|
This NIP now has wider support than the majority of approved NIPs did before they were merged, and more support than a handful of the "approved" NIPs do years after they were merged. |
|
@dskvr have you thought about a similar filter but limited by only the mentioned tags? For instance, I want all the kind 1s that cited Myself and Amethyst's key in the same event, but no other p tags. |
|
@vitorpamplona I will not be making any functional amendments to this NIP. |
|
Sorry, this shouldn't have been merged. Rewriting history now. |
|
HAHAHAHAHAHAHAHAHAHAHAHA @staab @vitorpamplona @eskema could you reopen it please? |
|
I don't have the button, you'll have to open a new one. |
|
@fiatjaf for all the "centralization slippery slope" talk you are definitely not leading by example by rewriting history because you don't like a widely-adopted NIP 🥇 |
|
Is it widely adopted though? I see one relay signaling support on nostr.watch |
|
@hzrd149 yes, I agree. I merged because this looks good and technically meets the requirements in the readme, but fiatjaf is right that it isn't really "widely adopted" (at least I don't see any evidence that it is). I don't want to argue about it, I'm not interested in this NIP so I'm just not going to participate any more, but I can't reopen because github won't let me. |
|
That's what draft PRs are for you melon. There were several implementations by the time it was merged. |
|
It's a good idea that should have been part of NIP-01 to begin with. But the problem with it is that it changes the NostrFilter interface, one of the 2 only core interfaces to the Nostr protocol. Meaning that every Nostr library in existence would have to be updated. At this point I think it would be exciting to see a big change like this, though. Give Nostr devs something to do lol. |
|
@alexgleason The way applesauce did it was simple and elegant. Clients can support There's an open PR to nostr-tools, but it will never be merged. There are also 2 open PRs to I didn't even expect this to be merged, basically ever, I said that much a year ago higher up in the thread. At least until the acceptance was wide enough that it was obvious. But how things have unfolded speak louder than words:
^ 1-4 occurred over a time-period of 48 hours. This is the kind of behavior one expects from despots, not the maintainer of a self-proclaimed "decentralized" and "self-sovereign" protocol. If |


Filter operand that has optimization benefits for relays, users and developers. Likely contentious.
This NIP is the result of convergent efforts. I wrote this NIP because it seemed obvious but didn't submit because I didn't have an implementation, @v0l wrote an implementation(*) around the same time. @lez connected the dots.
Rendered NIP
Discourse
Implementations
pending
Rationale
meme AND catobjectively consumes less bandwidth thanmeme OR catANDis fast for all common index formats, and faster compared toORfor some index formats. (See section below)Considerations
NIP-11.limitations:max_tags_per_andandmax_tags_andIndex Efficiency