To find semantic duplicates in a knowledge base, keep article IDs, break the content into short semantic blocks, and use Sentence Transformers to generate pairs of similar texts. Then the editor must compare the response conditions and decide which records to merge. A high similarity score by itself does not justify deletion: two articles may describe the same action for different plans.
Instructions for a corporate knowledge base editor and a developer preparing content cleanup before updating search or a RAG assistant. Prepared on November 6, 2026, publisher — Vladimir Lomtev's AI Studio. Below is the documented process and sample training code. The model was not run on the company corpus by the editorial team; duplicate-detection quality and processing time were not measured.
Contents
- Step 1. Define which records may be merged
- Step 2. Prepare short blocks without losing conditions
- Step 3. Set up the environment and pin the model
- Step 4. Generate candidate pairs
- Step 5. Check whether output is constrained by parameters
- Step 6. Review the pairs and document the merge
- Step 7. Validate the result against user questions
Step 1. Define which records may be merged
First, define the duplicate rule for your knowledge base. A workable approach is this: records may be merged if they answer the same user task, contain compatible conditions, and preserve all material restrictions after merging. Topic overlap is only a reason to compare the texts.
For example, “How do I change my payment card” and “How do I update the card for recurring charges” may be duplicates. But an instruction for a company administrator and an instruction for an employee may require different permissions. Merging them without explanation could make the answer incorrect.
Save the original export and work from a copy. For each record, keep a persistent id, title, text, source link, effective date, product, plan, and audience. This is a proposed data schema: Sentence Transformers does not require exactly these business fields. They are needed so the editor can restore context after search.
The output of this step is a table of records and a merge rule. If two editors interpret the word “duplicate” differently, first review a few disputed pairs, then run the full-corpus processing.
Step 2. Prepare short blocks without losing conditions
Remove technical HTML markup, identical menus, and repeating footers. Preserve negations, numbers, plan names, and exceptions. Do not turn “refund allowed” and “refund not allowed” into the same string through aggressive normalization.
For the first pass, use short Q&A cards or separate complete sections. In the paraphrase-multilingual-MiniLM-L12-v2 card the vector size is listed as 384 and max_seq_length is 128. These are parameters of a specific model, not universal embedding limits. Long text may be truncated, so matching openings do not confirm matching conditions at the end of the document.
If you need to split long documents, keep article_id and a separate chunk_id. A pair of similar fragments does not mean the full articles are interchangeable. First review the parent materials in full.
You can pre-group exact text matches by comparing strings while preserving all original IDs. Even here, different effective dates or audiences still require an editorial decision. The goal of preparation is to eliminate unnecessary comparisons while preserving the provenance of each record.
Step 3. Set up the environment and pin the model
This example uses Python and the Sentence Transformers library. The official installation instructions describe installation via pip; check Python and dependency compatibility there before running it in your environment. Start with a separate virtual environment:
python -m venv .venv
source .venv/bin/activate
python -m pip install -U sentence-transformers
The activation commands are for bash. This is a documentation-based instruction, not a record of an actual installation performed by the editorial team. After installation succeeds, save the dependency versions with the command python -m pip freeze > requirements.txt, so the rerun can be matched to the original.
The starter candidate is sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2. The pretrained model catalog classifies it as a multilingual model for semantic similarity. That does not prove quality on your company's Russian-language policies. Choosing a model for user-question search is a separate task; see the embedding selection checklist for RAG.
When loading, the model may be downloaded from a repository. Decide in advance where the model and text-processing assets will be stored. For a reproducible production run, the revision parameter in the constructor lets you specify a revision; its purpose is described in the SentenceTransformer reference guide. Save the actual revision together with the results.
Step 4. Generate candidate pairs
The documentation calls paraphrase search in a corpus *paraphrase mining*. The example below adapts this mechanism to knowledge base cards. The texts are fictional; no numeric results are provided intentionally, since the model was not run here.
import csv
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import paraphrase_mining
records = [
{"id": "kb-card", "text": "How do I change the card used for subscription payments?"},
{"id": "kb-payment", "text": "How do I replace the subscription payment card?"},
{"id": "kb-refund", "text": "When will I get a refund after canceling the subscription?"},
{"id": "kb-admin", "text": "Who can change the company's payment card?"},
]
assert len({r["id"] for r in records}) == len(records)
assert all(r["text"].strip() for r in records)
model = SentenceTransformer(
"sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
)
pairs = paraphrase_mining(
model,
[r["text"] for r in records],
top_k=3,
max_pairs=20,
)
with open("candidate_pairs.csv", "w", encoding="utf-8-sig", newline="") as f:
writer = csv.writer(f)
writer.writerow(["score", "id_a", "id_b", "text_a", "text_b"])
for score, i, j in pairs:
writer.writerow([
float(score), records[i]["id"], records[j]["id"],
records[i]["text"], records[j]["text"],
])
According to the paraphrase mining guide, the function returns triples: a similarity score and two text indices. The indices refer to the list you passed in, so the order of records cannot change between calculation and export.
A successful technical run will create a CSV with a header and the returned pairs whose IDs exist in the source data. Check this before the editorial review. The presence of the file confirms that export works, but not that the model is good. The numbers 3 and 20 are chosen here for a small training example, not as production-corpus settings.
Step 5. Check whether output is constrained by parameters
The API reference for util describes top_k, max_pairs, comparison block sizes, and the similarity function. top_k limits the neighbors considered, and max_pairs — the number of returned pairs. These limits affect how complete the candidate list is. The absence of a pair in the CSV does not prove that their texts differ in meaning.
If the editor already knows several duplicates, check whether they appear in the results. If not, review text length, wording differences, the model, and search constraints. Expanding the candidate list may increase the editor’s workload; it is useful to compare not only the number of matched pairs, but also the number of records suitable for merging.
For large corpora, the guide describes block-based processing, which makes it possible to avoid storing the entire comparison matrix at once. This is not a promise of linear runtime. Do not extrapolate the execution time from four rows to the entire database: you need a separate benchmark on your own hardware and dataset size.
Step 6. Review the pairs and document the merge
Add the fields decision, reason, canonical_idto the CSV. Suggested decisions: “merge,” “keep separate,” “owner review needed.” Sorting by similarity helps you start the review, but the final decision depends on the content.
| What was found | Editor decision | What to keep |
|---|---|---|
| One answer phrased differently | Merge after checking the conditions | The primary record and the mapping to the new record from the old IDs |
| One process for different pricing plans | Split it or clearly describe the branches | The limitations of each plan |
| Conflicting versions of the instructions | Escalate to the process owner | Both versions until the decision on which is current |
| Only the opening paragraph matched | Compare the full materials | The unique sections of each article |
Do not automatically merge an entire chain as a group: if A is close to B, and B is close to C, that does not mean A and C are interchangeable. Review each item against the chosen primary record. Otherwise, incompatible conditions may end up in the merged article.
Before applying changes, prepare the final record card and the list of links that need to be updated. Old IDs should not disappear without a trace from the processing history. If the database is used in RAG, treat text updates and removal of old fragments from the index as a separate operation: the finished CSV on its own does not change the search index.
Step 7. Check the result against user questions
Take the questions that the merged articles answered and find the answers in the updated database. Check whether access rights, pricing plan terms, and exceptions were preserved. For materials with different audiences, ask one question from the perspective of each role.
The completion criterion for this task is agreed-upon pairs, preserved source records, selected primary records, and accessible answers after the changes. Decide in advance what share of incorrect merges the process can tolerate at all; there is no universal safe similarity threshold here.
If you need an automatic threshold, prepare a separate labeled set of pairs and evaluate errors on data not used to tune it. Embedding similarity is not the probability of a duplicate. This guide does not propose a numeric threshold: without validation on your corpus, it would create unwarranted confidence.
How Vladimir Lomtev’s AI studio helps prepare a knowledge base
Vladimir Lomtev’s AI studio can connect data preparation with the development of an enterprise knowledge base: organize exports with persistent IDs, build handling for coordinated changes into the RAG system, and verify answers after updates. These steps relate to data preparation, integration, and testing; the quality of a specific model requires separate evaluation.
The first step is to choose one knowledge base, describe its current issues, sources, processing constraints, and the criterion for a successful merge. Discuss the project.
Bottom line: the candidate list should lead to clear changes
Start with short records and stable IDs, obtain pairs, compare the material differences, and only then merge the content. The result of the work is updated answers with preserved provenance. The similarity CSV is a screening tool for the editor; its numeric scores need to be validated on real examples from your own database.


