An NFT's "collection" field is stored on it's Metadata Account, so you would need to build and an instruction that requires the Metadata Account for the NFT to be provided to the instruction.
Here's metaplex docs for reference of how collections currently work: https://docs.metaplex.com/programs/token-metadata/certified-collections
You would then need the deserialized account data from the Metadata Account, which is now supported as part of Anchor 0.26:
#[account(
seeds = [b"metadata", mpl_token_metadata::ID.as_ref(), mint.key().as_ref()],
seeds::program = mpl_token_metadata::ID,
bump,
)]
pub metadata_account: Account<'info, MetadataAccount>
https://github.com/coral-xyz/anchor/pull/2014
https://github.com/coral-xyz/anchor/blob/master/CHANGELOG.md
Then within your instruction, check that the "collection" field on the Metadata Account matches the "collection" you expect.
Note that you may also need to check if the "collection" field on the Metadata Account has been verified. This is because anyone can create an NFT and set the "collection" field to any address they want.
From the metaplex docs:
As mentioned above, the Collection field contains a Verified boolean
which is used to determine if the NFT is truly part of the collection
it points to. Without this field, anyone could pretend their NFT to be
part of any collection.
In order to flip that Verified boolean to True, the Authority of the
Collection NFT must sign the NFT to prove that it is allowed to be
part of the collection.