Intersection of words
You should declare variables in the smallest possible scope. E.g. instead of

String family;
for  (...) {
    family = ...;
    ...
}


we could do

for (...) {
    String family = ...;
    ...
}


The same applies to docInfo, doc1, doc2, sorted, intersectionWords, different, and index.

You have this snippet:

Iterator&lt;String&gt; iterator = different.iterator();
while (iterator.hasNext()) {
    String s = iterator.next();
    ...
}


which could be abbreviated to for (String s : different) { ... }.

If we clean up these two points, we end up with this:

public void setDocunents() {
    // Neighbor contain the arrayList of Documents
    neighbors.add(new Neighbor&lt;Integer&gt;("sky"));
    neighbors.add(new Neighbor&lt;Integer&gt;("earth"));

    try {
        Map&lt;Long, String&gt; docInfo = dbDocMeta.getDocInfo();
        for (Long id : docInfo.keySet()) {
            String family = docInfo.get(id).contains("sky") ? "sky" : "earth";
            for (Neighbor&lt;Integer&gt; neighbor : neighbors) {
                // check if the document in the Neighbour family
                if (neighbor.getFamily().equalsIgnoreCase(family)) {
                    HashSet&lt;String&gt; different = new HashSet&lt;String&gt;();
                    different.addAll(someWord);
                    Document&lt;String&gt; doc1 = dbWords.getNeighbors(id);
                    Document&lt;Integer&gt; doc2 = new Document&lt;Integer&gt;();
                    ArrayList&lt;String&gt; intersectionWords = new ArrayList&lt;String&gt;();
                    for (String word : doc1.getMap().keySet()) {
                        int index = dbWords.getIndex(word);
                        if (selectedFeatures.contains(word)) {
                            doc2.add(index, doc1.getAttributes().get(word));
                            intersectionWords.add(word);
                        }
                    }
                    if (!doc2.getMap().isEmpty()) {
                        different.removeAll(intersectionWords);
                        for (String s : different) {
                            int index = dbWords.getIndex(s);
                            doc2.add(index, 0);
                        }
                        Map&lt;Integer, Long&gt; sorted = new TreeMap&lt;Integer, Long&gt;(doc2.getAttributes());
                        doc2.setMap(sorted);
                        neighbor.addDocument(doc2);
                        break;
                    }
                }
            }
        }
    } catch (InterruptedException e) {
        logger.error("InterruptedException msg : {} \n {}", e.getMessage(), e.getStackTrace());
    } catch (ClassNotFoundException e) {
        logger.error("ClassNotFoundException msg : {} \n {}", e.getMessage(), e.getStackTrace());
    }
}


In a next step, we remove calculations from inner loops that don't have to be recalculated each time. E.g. doc1 = dbWords.getNeighbors(id) depends only on id, and probably does not have to be called for each neighbor. On the other hand, different is only needed inside a specific if branch.

Furthermore, doc2 will be discarded unless that branch is entered, so we will build it only in that case (assuming doc2.getMap().isEmpty() is equivalent to intersectionWords.isEmpty().

We can further remove unnecessary variables – their types just add clutter to the code.

A bare break inside nested loops can be a bit confusing, so we'll use the labelled for: break neighbors.

The HashSet constructor can directly take a collection, there is no need to separately call addAll.

If the whole body of a loop us subject to an if (cond), it is often easier to read when at the beginning of a loop, we if (!cond) continue.

Unrelated implementation details like calculating the intersection of two sets should be factored out into helper functions.

public void setDocunents() {
    // Neighbor contain the arrayList of Documents
    neighbors.add(new Neighbor&lt;Integer&gt;("sky"));
    neighbors.add(new Neighbor&lt;Integer&gt;("earth"));

    try {
        Map&lt;Long, String&gt; docInfo = dbDocMeta.getDocInfo();
        for (Long id : docInfo.keySet()) {
            String family = docInfo.get(id).contains("sky") ? "sky" : "earth";
            Document&lt;String&gt; doc1 = dbWords.getNeighbors(id);

            neighbors:
            for (Neighbor&lt;Integer&gt; neighbor : neighbors) {
                // check if the document in the Neighbour family
                if (!neighbor.getFamily().equalsIgnoreCase(family)) {
                    continue neighbors;
                }

                Set&lt;String&gt; intersectionWords = intersection&lt;String&gt;(doc1.getMap().keySet(), selectedFeatures);
                if (intersectionWords.isEmpty()) {
                    continue neighbors;
                }

                HashSet&lt;String&gt; different = new HashSet&lt;String&gt;(someWord);
                Document&lt;Integer&gt; doc2 = new Document&lt;Integer&gt;();
                for (String s : intersectionWords) {
                    doc2.add(dbWords.getIndex(word), doc1.getAttributes().get(word));
                    different.remove(s);
                }
                for (String s : different) {
                    doc2.add(dbWords.getIndex(s), 0);
                }
                // due to the choice of a TreeMap, the elements are sorted
                doc2.setMap(new TreeMap&lt;Integer, Long&gt;(doc2.getAttributes()));
                neighbor.addDocument(doc2);

                break neighbors;
            }
        }
    } catch (InterruptedException e) {
        logger.error("InterruptedException msg : {} \n {}", e.getMessage(), e.getStackTrace());
    } catch (ClassNotFoundException e) {
        logger.error("ClassNotFoundException msg : {} \n {}", e.getMessage(), e.getStackTrace());
    }
}

private static &lt;A&gt; Set&lt;A&gt; intersection(final Set&lt;A&gt; xs, final Set&lt;A&gt; ys) {
    // make sure that xs is the smaller set
    if (ys.size() &lt; xs.size()) {
        return intersection&lt;A&gt;(ys, xs);
    }

    final HashSet&lt;A&gt; result = new HashSet&lt;&gt;();
    for (A x : xs) {
        if (ys.contains(x)) {
            result.add(x)
        }
    }

    return result;
}


This could be optimized further, e.g. when doc2.add(…) has no side effects except setting the underlying map, or if the composition of someWord is known.