← all conversations

Document similarity approach

2025-07-313 turns4,915 charsgpt-4-1-mini, gpt-4o1 fork(s)
document-similarityembedding-searchcontent-deduplication

Summary

User wants to check for document similarity before adding new content to a store using an agent search approach.

Messages

⑂ thread forked here
https://github.com/kliewerdaniel/agentsearch01/blob/master/agent_search.py discuss how this might answer this question a couple of paragraphs :I'm working with a document store where I frequently upload new content. Before adding a new document, I want to check whether any existing document already discusses a similar topic or shares a similar context — essentially to avoid duplication or redundancy. I'm currently exploring embeddings and vectorstores for this purpose. The idea is to generate embeddings for the new document and compare them against the stored ones to detect semantic similarity. Has anyone implemented a reliable approach for this? What are the best practices or tools (e.g., similarity thresholds, chunking strategies, topic modeling, etc.) to improve the accuracy of such checks? Would love to hear how others are handling this scenario!
The [`agent_search.py`](https://github.com/kliewerdaniel/agentsearch01/blob/master/agent_search.py) script offers a practical and extensible approach to handling semantic similarity in a document store using LLM-driven agents. At its core, it sets up a framework where a query is first refined, then compared against existing search results, and finally analyzed for meaningful matches. This multi-step refinement and evaluation pipeline can be directly adapted to the task of semantic deduplication. When uploading a new document, you can treat its summary or full text as the "query," allowing the system to refine it, search the vectorstore for semantically similar documents, and analyze the overlap before deciding whether to add the new content. This allows for more nuanced comparison than a simple cosine similarity threshold—leveraging LLMs to interpret and summarize context can highlight deeper conceptual similarities or differences that traditional embedding comparison might miss. Best practices hinted at by the script include the use of multiple stages of refinement and analysis rather than relying solely on static embeddings. You might consider breaking documents into overlapping chunks (e.g., sliding windows of 200–500 tokens) and storing those in a vectorstore like ChromaDB or FAISS. Then, using a similar pipeline to `agent_search.py`, you can summarize or generate a query embedding from the new document and search the chunked index. The use of named agents for each stage—refinement, search, and analysis—suggests modular design is beneficial for maintainability and extensibility. You could, for example, add agents for topic modeling or metadata comparison as part of your deduplication pipeline. This architecture provides a strong foundation for handling semantic overlap intelligently, rather than with brittle heuristics.
gpt-4o
The `agent_search.py` script from the `agentsearch01` repo offers a practical framework that can definitely help address your need for detecting document similarity and avoiding redundancy in a document store. Essentially, it orchestrates a multi-step pipeline where an input query (or new document) undergoes iterative refinement, search over existing content, and analysis before delivering a final result. This modular approach aligns well with your goal of checking if newly uploaded documents cover topics already present. In your scenario, the key step is the similarity search: the script leverages embeddings to represent textual content in a vector space and performs similarity comparisons. The pipeline handles query refinement and integrates search results to analyze and validate similarity, potentially reducing false positives or missing relevant matches. The use of chunking (breaking documents into smaller segments) is implicit in how search results are returned and aggregated, which can help in pinpointing partial overlaps or nuanced contextual similarities instead of blunt whole-document matches. Best practices reflected here include combining semantic similarity with iterative refinement of queries, and possibly layering analysis steps to improve accuracy. Some takeaways from this approach for your use case: - **Embeddings + vector search** form the core similarity detection method, as you anticipated. - **Chunking documents** into smaller pieces before embedding allows finer-grained comparisons and avoids missing localized topic overlap. - **Iterative query refinement** or multiple passes can help clarify ambiguous or broad topics, improving match quality. - **Analyzing search results contextually** rather than just thresholding on raw similarity scores can help distinguish truly relevant redundancy from surface-level similarity. Overall, this script exemplifies a composable and extensible design for semantic search over document stores, incorporating best practices like chunking, refinement, and layered analysis that should enhance your detection of similar or redundant documents. It’s a strong example to adapt or build upon in your system.
gpt-4-1-mini