Better confidence intervals for weighted average Suppose I have a large sequence of size $M$ which contains $K$ unique items, where item $k$ occurs with unknown probability $\pi_k$. I can choose to measure its quality, $x_k$, which is constant for a given item $k$.
My goal is to estimate the average quality (i.e., the true weighted average as well as CI around it):
$$\sum_{k=1}^K \pi_k x_k$$
One plan is to get a uniform sample of items $J$ from this sequence, and compute the average over each sampled item (since item $k$ is sampled with probability $\pi_k$):
$$\frac{1}{|J|} \sum_{j \in J} x_j$$
and estimate the variance of the estimator using the usual CLT-based approach.
Suppose, however, it's also easy to compute the total number of times each item occurs, $(n_1, ..., n_K)$. Can I use this information to produce estimates with smaller confidence intervals?
Not to bias the potential answers, but I feel like it should be possible to do, since I will have more information about $\pi$, and therefore should be able to do some sort of variance reduction technique.
Also, to work through a specific example, I've been using the following distribution which mimics my actual usecase.
import numpy as np

# Suppose we K unique items
K=10000
freq = np.array([K/(i+100) for i in range(K)])
true_pi = freq / sum(freq)
true_x = np.array([.8 - .4*i/K for i in range(K)])

 A: An estimator that is obviously better in some ways is
$$\hat\mu= \frac{\sum_{\textrm{observed }k} n_kx_k}{\sum_{\textrm{observed }k} n_k}$$
In particular, if $|J|$ is large enough that all $K$ distinct items
will be observed at least once (with probability going to 1) and the
error of $\hat\mu$ will be exactly zero, where your estimator (call
it $\bar x$) has error of order $|J|^{-1/2}$.
On the other hand, for smaller values of $|J|$, $\hat\mu$ is not typically unbiased, which makes confidence intervals more difficult.
On the other other hand, $\hat \mu$ looks like it should typically have smaller mean absolute error or mean squared error.
What can we say analytically?
Write $\hat m_k$ for the number of times you observe an item of type $k$ and $\hat n_k=\hat m_kM/|J|$ for the expected value of $n_k$ given $\hat m_k$. Introduce $R_k$ as the indicator
of observing item $k$ at least once (so  $\hat n_k>0$).
Your estimator $\bar x$ can be written as
$$\bar x = \frac{\sum_{k=1}^K \hat m_kR_kx_k}{\sum_{k=1}^K \hat m_kR_k}$$
or equivalently as
$$\bar x = \frac{\sum_{k=1}^K \hat n_kR_kx_k}{\sum_{k=1}^K \hat n_kR_k}$$
and mine as
$$\hat\mu= \frac{\sum_{k=1}^K n_kR_kx_k}{\sum_{k=1}^K n_kR_k}$$
So we obtain $\hat\mu$ by replacing $\hat n_k$ with $n_k$.
Since $\hat n_k-n_k$ is independent of $\hat\mu$ and its distribution does not depend on the parameters $\{x_k\}$, it's pure noise and $\hat\mu$ is more accurate (but not, however, unbiased).
You can get confidence intervals for $\hat\mu$ ignoring the bias by using a bootstrap.  And you could use a subsampling bootstrap to get bias-corrected intervals.
A: 
estimate the variance of the estimator using the usual CLT-based approach.
...
Can I use this information to produce estimates with smaller confidence intervals?

Yes, you can. (This is true in general. In many cases, you can do better than a normal approximation, especially when the distribution is not really a normal distribution but just approximately)
How you are gonna do it exactly will depend on the situation.

It seems like you want to compute the average of the distribution of $x$ by taking a sample.
Classically your estimate will be based on a sample of size $n$ like $x_1, \dots x_n$, and then you compute the mean and standard error.
If the distribution of $x$ is assumed to be Gaussian (or approximately Gaussian, like most sample means are anyway), then you would use:
$$\begin{array}{}
\hat{\mu} &=& \bar{x} &=& \frac{1}{n} \sum_{i=1}^n x_i\\
\hat{\sigma}_\mu & =& \frac{1}{\sqrt{n}} s &=& \frac{1}{\sqrt{n}}  \sqrt{\frac{1}{n-1}\sum_{i=1}^n (x_i-\bar{x})^2}
\end{array}$$

But instead of the classical estimate of the error of the mean, you want to use some information about a special property of the data sampling which is that some of the items may occur multiple times.
The exact approach will depend on the type of joint distribution of $x_k,\pi_k$. But here we will show by means of two examples that indeed the estimates and the confidence interval can be treated differently.

Binomial distribution case
You might have a situation where there is only two items. Then the estimate of the mean all boils down to estimation of the probability $p$ for the 1st item (and $1-p$ for the second item). And the estimate of the mean becomes
$$\hat{\mu} = x_1 \hat{p} + x_2 (1-\hat{p}) = x_2 + \hat{p} (x_1 - x_2)$$
Where the estimate $\hat{p}$ relate to estimation of the parameter of a binomial distribution whose estimate of the standard error is different from the estimate of the standard error of mean. In fact there is a large variety of approaches (https://en.m.wikipedia.org/wiki/Binomial_proportion_confidence_interval).
In this example you know all the $x_k$ because you assume that there are only two items. In reality you may have something more complex like $\pi$ being some parametric probability function/density/mass $f(x)$ telling you how probable a certain value (or range) $x$ is. And your estimate of the average of $x$ will boil down to being an estimate of the average of the distribution/function $\pi$. Depending on the type of distribution $\pi$ you will get different types of estimates and confidence intervals.

Independent $\pi$ and $x$
It could be that the items are distributed with $\pi$ and $x$ independently. Your sample could have some item $k$ occuring multiple times, but this will be partly random/noisy behaviour that tells you little about the true weighted mean.
Because of the independence of $\pi$ and $x$ you will only be interested in the distribution of $x$ and not the $\pi$. So you can estimate the mean by only considering the $m$ unique items in the sample and not all the $n$ items (ie. you ignore multiplicity)
$$\begin{array}{}
\hat{\mu} &=& \bar{x} &=& \frac{1}{m} \sum_{i=1}^m x_i\\
\hat{\sigma}_\mu & =& \frac{1}{\sqrt{m}} s &=& \frac{1}{\sqrt{m}}  \sqrt{\frac{1}{m-1}\sum_{i=1}^m (x_i-\bar{x})^2}
\end{array}$$
Example computation
Let $x_k \sim N(\mu,\sigma^2)$ and independent relative frequencies $y_k \sim Uniform(a,b)$ from which we compute the normalised frequencies $\pi_k = \frac{y_k}{\sum y_k}$. Say we have 10 000 items according to this distribution and in order to estimate $\sum_{i=1}^{10000} x_i\pi_i$ we sample 5 000 times an item (with repetition).
With a simulation we can see that there can be a difference in the error with the classical estimate and the alternative estimate, with the latter being closer to zero (see the sharper distribution):

### number of repetitions
r <- 10000

### function to create fditribution with 10 000 items
items <- function(mu = 0, sigma = 1, a = 0, b = 1) {
  x <- rnorm(10000,mu,sigma) 
  y <- runif(10000,a,b)
  p <- y/sum(y)
  return(list(x=x,p=p))
} 

### vectors to store results
v_mu   <- rep(0,r)
v_est1 <- rep(0,r)
v_est2 <- rep(0,r)
  
### repeat estimation several times
set.seed(1)
for (trial in 1:r) {
  ### create distribution
  example <- items(a=1,b=1.5)
  
  ### true mean
  mu <- sum(example$x*example$p)
  
  ### sample 5000 items 
  k <- sample(1:10000, 5000, replace = TRUE, p = example$p)
  unique <- as.numeric(labels(table(k))$k)
  
  ### traditional estimate
  est1 <- mean(example$x[k])
  ### alternative estimate
  est2 <- mean(example$x[unique])
  
  ### store results
  v_mu[trial] <- mu
  v_est1[trial] <- est1
  v_est2[trial] <- est2
}


### plotting
h1 <- hist(v_est1-mu, breaks = seq(-0.2,0.2,0.005)) 
h2 <- hist(v_est2-mu, breaks = seq(-0.2,0.2,0.005)) 

plot(h2$mids,(h2$density),type="l", log = "",
     xlab = "error of estimate", ylab = "density", xlim = c(-1,1)*0.15)
lines(h1$mids,(h1$density),lty = 2)

legend(-0.15,25, c("with repetitions","without repetitions"),
       lty = c(2,1),cex = 0.7)

Note that this effect will depend a lot on the particular distribution of $\pi$. In this example $\pi \sim U(1,1.1)$, which is not much variation between the different $\pi_k$ and the variance of duplicity is more noise than reflecting a true difference in $\pi_k$. You can change it a bit (e.g. use $\pi \sim U(0,1)$ or an entirely different distribution) and then the effect becomes less pronounced, or even negative. Anyway, the example in this answer shows that there will be differences in estimators and potential improvements can be made (but it will depend a lot on the knowledge of the particular underlying distribution how you are gonna approach the estimation).
