Graph-Based Product Search with LLMs: Architecture and Examples
Product search based on text queries must handle requests that are 1–2 sentences long. Expected scenarios include simple queries ("jeans"), semantic search (sweater → sweatshirts), negations ("dress not made of cotton"), adjectives ("stunning dress"), structured descriptions ("long dress with short sleeves"), multiple entities ("white top and blue jeans"), purpose-based queries ("shoes for sports"), brand/price mentions ("Kors bag under 20k"), and references to public figures ("bag like Dua Lipa's").
Such queries go beyond keyword and vector search, requiring analysis of relationships and context.
Advantages of Graph Representation
Graphs store not only entities but also the relationships between them. For a query like "tank top," a product description stating "Levi's jeans, pairs well with a top" won't yield a false positive match: in the query graph, "tank top" is linked to the main object, but in the product, it isn't. The graph2graph similarity metric accounts for this, lowering the score.
For "jeans," the score is high due to semantic alignment of structures.
Graphs allow for distinguishing node roles: desired product, undesired attribute, part of an object.
LLM Graph Search Pipeline
The algorithm consists of sequential steps:
- Dynamic prompts optimization: Analyzes query complexity, extracts brands/prices. For simple queries (1–2 words), falls back to keyword or vector search. Forms a prompt for Text2Graph.
- Text2Graph: LLM constructs a knowledge graph from the query. Splits into subgraphs for multiple entities.
- Graph search: Compares the query graph with product graphs using graph2graph similarity. Outputs top-N indices.
- LLM ranker: Re-ranks candidates to improve accuracy.
- Result evaluation: Analyzes matches/mismatches (found type but not color). If score is low, iterates or falls back.
Latency of 10–15 seconds is acceptable for RAG-like systems.
Examples of Complex Query Processing
Negations
Query: "elegant long dress without sleeves." The graph marks "sleeves" as an undesired attribute. Search excludes products with sleeves, focusing on dresses with attributes "elegant," "long."
Structured Queries
"Long dress with short sleeves." Graph: dress (long) → sleeves (short). The algorithm finds products with hierarchical structure, without depth limitations. Useful for documents with nested conditions (applications with filters by status/dates).
Multiple Entities
"White jeans and blue bag." Text2Graph splits into subgraphs, search runs in parallel. Matching sets is possible (blue suit for "blue jacket and blue pants"), but requires refinement in evaluation to avoid false fallbacks.
Purpose Without Type
"Shoes for sports." The graph expands to usage scenario, matches by semantics.
Brands and Price
"Levi's jeans under 12k." Filters are extracted in Text2Graph, integrated into the graph. Textual evaluations ("cheap") are based on statistics of similar products.
Key Takeaways
- Graph search outperforms vector search in structured queries with negations and relationships.
- The pipeline is domain-independent (except prompt optimization), adaptable to books/documents.
- Result evaluation allows iterations without showing the user.
- Latency reduces to 2–3 seconds with vectorization and optional ranker.
- Future prospects: complexity-based routing, multimodal models, deep research.
— Editorial Team
No comments yet.