Coffee can be difficult to remove due to the natural tannin dye. There are three methods commonly used. A home remedy is to apply vinegar and blot with a white towel. Diluting a carpet acidic rinse liquid 1:5 works on most easy spots. Commercial coffee stain removers are normally effective on difficult or pre-cleaned spills. However, the active ingredient, sodium metabisulfite can bite your nose and is considered hazardous to breathe.
One way to permanently set a coffee stain is to use a high pH cleaner, so if the spot has been repeatedly cleaned, you may be out of luck. Often, coffee stains must be removed at elevated temperatures close to the temp at which they entered the fiber. Formulations from carpet cleaning supply firms usually require mixing with hot water just prior to use, pre-testing the fabric for colorfastness in an inconspicuous area, and then applying directly to the spill. Try to avoid breathing the fumes. If the label specifies, you apply moderately (just enough to cover, but not soak, the spot) and then vacuum when dry.