{
  "title": "Pinecone और LLMs के साथ E-Commerce के लिए Hybrid Search",
  "excerpt": "जानें कि कैसे पारंपरिक information retrieval विधियों को Language Models (LLMs) जैसे machine learning models और Pinecone, एक managed vector database, के साथ मिलाकर e-commerce applications के लिए एक शक्तिशाली hybrid search system बनाया जा सकता है। E-commerce के लिए hybrid search के लाभों को खोजें, जिसमें improved search relevance, personalization, long-tail queries को संभालना, और simpler infrastructure management शामिल है।",
  "content_html": "<p>किसी भी e-commerce वेबसाइट के लिए प्रासंगिक उत्पादों को खोजना और ढूंढना एक महत्वपूर्ण हिस्सा है। तेज़ और सटीक search results उपलब्ध कराना high user satisfaction और user frustration के बीच का अंतर तय कर सकता है। natural language understanding और vector search technologies में हालिया प्रगति के साथ, बेहतर search systems अधिक सुलभ और कुशल हो गए हैं, जिससे बेहतर user experiences और improved conversion rates मिल रहे हैं।</p>\n<p>इस blog post में, हम यह जानेंगे कि Pinecone, एक high-performance vector search engine, और fine-tuned domain-specific language models का उपयोग करके e-commerce के लिए एक hybrid search system कैसे लागू किया जाए। इस post के अंत तक, आपको न केवल hybrid search की गहरी समझ होगी, बल्कि इसे लागू करने के लिए एक व्यावहारिक step-by-step guide भी मिलेगा।</p>\n<h2>Hybrid Search क्या है?</h2>\n<img src=\"/assets/images/pinecone_hybrid_index.jpg\" class=\"post-img\" width=\"2360\" height=\"921\" />\n<span class=\"post-img-caption\">Simple Pinecone Hybrid Index का high-level view</span>\n<p>Implementation में गोता लगाने से पहले, आइए जल्दी से समझें कि hybrid search का क्या मतलब है। Hybrid search एक ऐसा approach है जो traditional search (sparse vector search) और vector search (dense vector search) दोनों की ताकतों को मिलाकर विभिन्न domains में बेहतर search performance हासिल करता है।</p>\n<p>Dense vector search text data से high-quality vector embeddings निकालता है और relevant documents खोजने के लिए similarity search करता है। हालांकि, जब यह domain-specific datasets पर fine-tuned नहीं होता है, तो यह अक्सर out-of-domain data के साथ संघर्ष करता है।</p>\n<p>दूसरी ओर, traditional search sparse vector representations का उपयोग करता है, जैसे कि term frequency-inverse document frequency (TF-IDF) या BM25, और इसे किसी भी domain-specific fine-tuning की आवश्यकता नहीं होती है। हालांकि यह नए domains को संभाल सकता है, लेकिन शब्दों के बीच semantic relations को समझने में असमर्थ होने के कारण इसकी performance सीमित रहती है और इसमें dense retrieval की intelligence का अभाव होता है।</p>\n<p>Hybrid search इन दोनों approaches की कमज़ोरियों को कम करने की कोशिश करता है उन्हें एक single system में मिलाकर, जिसमें dense vector search की performance potential और traditional search की zero-shot adaptability का लाभ उठाया जाता है।</p>\n<p>अब जब हमें hybrid search की बुनियादी समझ हो गई है, तो आइए इसके implementation में गोता लगाएं।</p>\n<h2>Hybrid Search System बनाना</h2>\n<p>हम hybrid search system को लागू करने के लिए निम्नलिखित steps को कवर करेंगे:</p>\n<ol>\n<li>Domain-Specific Language Models का लाभ उठाना</li>\n<li>Sparse और Dense Vectors बनाना</li>\n<li>Pinecone सेट अप करना</li>\n<li>Hybrid Search Pipeline को लागू करना</li>\n<li>Queries बनाना और Parameters को ट्यून करना</li>\n</ol>\n<h3>1. Domain-Specific Language Models का लाभ उठाना</h3>\n<p>हाल के वर्षों में, OpenAI's GPT और Cohere जैसे large-scale pre-trained language models विभिन्न tasks के लिए तेज़ी से लोकप्रिय हो रहे हैं, जिनमें natural language understanding और generation शामिल है। इन models को domain-specific data पर fine-tune किया जा सकता है ताकि उनकी performance बेहतर हो सके और वे specific tasks, जैसे कि e-commerce product search, के अनुकूल बन सकें।</p>\n<p>हमारे उदाहरण में, हम products और queries के लिए dense vector embeddings जनरेट करने के लिए एक fine-tuned domain-specific language model का उपयोग करेंगे। हालांकि, आप अपने specific domain के आधार पर अन्य models चुन सकते हैं या अपनी खुद की custom embeddings भी बना सकते हैं।</p>\n<pre><code class=\"language-python\">import torch\nfrom transformers import AutoTokenizer, AutoModel\n\n# Load a pre-trained domain-specific language model\nmodel_name = \"your-domain-specific-model\"\ntokenizer = AutoTokenizer.from_pretrained(model_name)\nmodel = AutoModel.from_pretrained(model_name)\n\n# Generate dense vector embeddings for a product description\ntext = \"Nike Air Max sports shoes for men\"\ninputs = tokenizer(text, return_tensors=\"pt\")\nwith torch.no_grad():\n    outputs = model(**inputs)\n    dense_embedding = outputs.last_hidden_state.mean(dim=1).numpy()</code></pre>\n<h3>2. Sparse और Dense Vectors बनाना</h3>\n<p>Hybrid search के लिए हमारे e-commerce data के लिए sparse और dense vector representations दोनों की आवश्यकता होती है। अब हम बताएंगे कि ये vectors कैसे जनरेट किए जाते हैं।</p>\n<h4>Sparse Vectors</h4>\n<p>TF-IDF या BM25 जैसे sparse vector representations को standard text processing techniques, जैसे कि tokenization, stopword removal, और stemming, का उपयोग करके बनाया जा सकता है। Sparse vectors जनरेट करने का एक उदाहरण vocabulary matrix का उपयोग करके हासिल किया जा सकता है।</p>\n<pre><code class=\"language-python\"># This function generates sparse vector representations of a list of product descriptions\ndef generate_sparse_vectors(text):\n    '''Generates sparse vector representations for a list of product descriptions\n\n    Args:\n        text (list): A list of product descriptions\n\n    Returns:\n        sparse_vector (dict): A dictionary of indices and values\n    '''\n    sparse_vector = bm25.encode_queries(text)\n    return sparse_vector\n\nfrom pinecone_text.sparse import BM25Encoder\n\n# Create the BM25 encoder and fit the data\nbm25 = BM25Encoder()\nbm25.fit(new_df.full_data)\n\n# Create the sparse vectors\nsparse_vectors = []\nfor product_description in product_descriptions:\n    sparse_vectors.append(generate_sparse_vectors(text=product_description))</code></pre>\n<h4>Dense Vectors</h4>\n<p>Dense vector representations को pre-trained या custom domain-specific language models का उपयोग करके जनरेट किया जा सकता है। हमारे पिछले उदाहरण में, हमने एक product description के लिए dense vector embeddings जनरेट करने के लिए एक domain-specific language model का उपयोग किया था।</p>\n<pre><code class=\"language-python\">def generate_dense_vector(text):\n    '''Generates dense vector embeddings for a list of product descriptions\n\n    Args:\n        text (list): A list of product descriptions\n\n    Returns:\n        dense_embedding (np.array): A numpy array of dense vector embeddings\n    '''\n    # Tokenize the text and convert to PyTorch tensors\n    inputs = tokenizer(text, return_tensors=\"pt\")\n    # Generate the embeddings with the pre-trained model\n    with torch.no_grad():\n        outputs = model(**inputs)\n        dense_vector = outputs.last_hidden_state.mean(dim=1).numpy()\n    return dense_vector\n\n# Generate dense vector embeddings for a list of product descriptions\ndense_vectors = []\nfor product_description in product_descriptions:\n    dense_vectors.append(generate_dense_vector(text=product_description))</code></pre>\n<h3>3. Pinecone सेट अप करना</h3>\n<p>Pinecone एक high-performance vector search engine है जो hybrid search को सपोर्ट करता है। यह sparse और dense vectors दोनों के लिए एक single index बनाने में सक्षम बनाता है और विभिन्न data modalities के बीच search queries को seamlessly संभालता है।</p>\n<p>Pinecone का उपयोग करने के लिए, आपको एक account के लिए sign up करना होगा, Pinecone client इंस्टॉल करना होगा, और अपनी API key और environment सेट अप करना होगा।</p>\n<pre><code class=\"language-python\"># Create a Pinecone hybrid search index\nimport pinecone\n\npinecone.init(\n    api_key=\"YOUR_API_KEY\",  # app.pinecone.io\n    environment=\"YOUR_ENV\"  # find next to api key in console\n)\n\n# Create a Pinecone hybrid search index\nindex_name = \"ecommerce-hybrid-search\"\npinecone.create_index(\n    index_name = index_name,\n    dimension = MODEL_DIMENSION,  # dimensionality of dense model\n    metric = \"dotproduct\"\n)\n# connect to the index\nindex = pinecone.Index(index_name=index_name)\n# view index stats\nindex.describe_index_stats()</code></pre>\n<h3>4. Hybrid Search Pipeline को लागू करना</h3>\n<p>हमारे sparse और dense vectors जनरेट हो जाने और Pinecone के सेट अप हो जाने के साथ, अब हम एक hybrid search pipeline बना सकते हैं। इस pipeline में निम्नलिखित steps शामिल हैं:</p>\n<ol>\n<li>Pinecone index में product data जोड़ना</li>\n<li>Sparse और dense vectors दोनों का उपयोग करके results retrieve करना</li>\n</ol>\n<pre><code class=\"language-python\">def add_product_data_to_index(product_ids, sparse_vectors, dense_vectors, metadata=None):\n    \"\"\"Upserts product data to the Pinecone index.\n\n    Args:\n        product_ids (`list` of `str`): Product IDs.\n        sparse_vectors (`list` of `list` of `float`): Sparse vectors.\n        dense_vectors (`list` of `list` of `float`): Dense vectors.\n        metadata (`list` of `list` of `str`): Optional metadata.\n\n    Returns:\n        None\n    \"\"\"\n    batch_size = 32\n\n    # Loop through the product IDs in batches.\n    for i in range(0, len(product_ids), batch_size):\n        i_end = min(i + batch_size, len(product_ids))\n        ids = product_ids[i:i_end]\n        sparse_batch = sparse_vectors[i:i_end]\n        dense_batch = dense_vectors[i:i_end]\n        meta_batch = metadata[i:i_end] if metadata else []\n\n        vectors = []\n        for _id, sparse, dense, meta in zip(ids, sparse_batch, dense_batch, meta_batch):\n            vectors.append({\n                'id': _id,\n                'sparse_values': sparse,\n                'values': dense,\n                'metadata': meta\n            })\n\n        # Upsert the vectors into the Pinecone index.\n        index.upsert(vectors=vectors)\n\nadd_product_data_to_index(product_ids, sparse_vectors, dense_vectors)</code></pre>\n<p>अब जब हमारा data indexed हो गया है, तो हम hybrid search queries कर सकते हैं।</p>\n<h3>5. Queries बनाना और Parameters को ट्यून करना</h3>\n<img src=\"/assets/images/pinecone_hybrid_query.jpg\" class=\"post-img\" width=\"2360\" height=\"892\" />\n<span class=\"post-img-caption\">Simple Pinecone Hybrid Query का high-level view</span>\n<p>Hybrid search queries बनाने के लिए, हम एक function बनाएंगे जो एक query, top results की संख्या, और एक alpha parameter लेता है ताकि dense और sparse vector search scores के बीच weighting को नियंत्रित किया जा सके।</p>\n<pre><code class=\"language-python\">def hybrid_scale(dense, sparse, alpha: float):\n    \"\"\"Hybrid vector scaling using a convex combination\n\n    alpha * dense + (1 - alpha) * sparse\n\n    Args:\n        dense: Array of floats representing\n        sparse: a dict of `indices` and `values`\n        alpha: float between 0 and 1 where 0 == sparse only\n               and 1 == dense only\n    \"\"\"\n    if alpha &lt; 0 or alpha &gt; 1:\n        raise ValueError(\"Alpha must be between 0 and 1\")\n    # scale sparse and dense vectors to create hybrid search vecs\n    hsparse = {\n        'indices': sparse['indices'],\n        'values':  [v * (1 - alpha) for v in sparse['values']]\n    }\n    hdense = [v * alpha for v in dense]\n    return hdense, hsparse\n\ndef search_products(query, top_k=10, alpha=0.5):\n    # Generate sparse query vector\n    sparse_query_vector = generate_sparse_vector(query)\n\n    # Generate dense query vector\n    dense_query_vector = generate_dense_vector(query)\n\n    # Calculate hybrid query vector\n    dense_query_vector, sparse_query_vector = hybrid_scale(dense_query_vector, sparse_query_vector, alpha)\n\n    # Search products using Pinecone\n    results = index.query(\n        vector=dense_query_vector,\n        sparse_vector=sparse_query_vector,\n        top_k=top_k\n    )\n\n    return results</code></pre>\n<p>फिर हम इस function का उपयोग अपने e-commerce dataset में relevant products खोजने के लिए कर सकते हैं।</p>\n<pre><code class=\"language-python\">query = \"running shoes for women\"\nresults = search_products(query, top_k=5)\n\nfor result in results:\n    print(result['id'], result['metadata']['product_name'], result['score'])</code></pre>\n<p>Alpha parameter के लिए विभिन्न values के साथ प्रयोग करने से आपको अपने specific domain के लिए sparse और dense vector search के बीच optimal balance खोजने में मदद मिलेगी।</p>\n<h2>निष्कर्ष</h2>\n<p>इस blog post में, हमने दिखाया कि Pinecone और domain-specific language models का उपयोग करके e-commerce के लिए एक hybrid search system कैसे बनाया जाए। Hybrid search हमें traditional search और vector search दोनों की ताकतों को मिलाने में सक्षम बनाता है, जिससे विभिन्न domains में search performance और adaptability बेहतर होती है।</p>\n<p>इस post में दिए गए steps और code snippets का पालन करके, आप अपनी e-commerce website की specific requirements के अनुसार अपना खुद का hybrid search system लागू कर सकते हैं। आज ही Pinecone को explore करना शुरू करें और अपने e-commerce search experience को बेहतर बनाएं!</p>\n<h2>संदर्भ</h2>\n<ul>\n<li><a href=\"https://colab.research.google.com/github/pinecone-io/examples/blob/master/search/hybrid-search/ecommerce-search/ecommerce-search.ipynb\">Ecommerce Search using Hybrid Search Techniques in Pinecone (Google Colab Notebook)</a>: Pinecone की hybrid search techniques का उपयोग करके e-commerce search के implementation को दिखाने वाली एक व्यावहारिक guide।</li>\n<li><a href=\"https://docs.pinecone.io/docs/ecommerce-search\">Pinecone Ecommerce Search Documentation</a>: E-commerce search systems बनाने के लिए Pinecone की official documentation।</li>\n<li><a href=\"https://colab.research.google.com/github/pinecone-io/examples/blob/master/pinecone/sparse/bm25/bm25-vector-generation.ipynb\">BM25 Vector Generation using Pinecone (Google Colab Notebook)</a>: Pinecone का उपयोग करके BM25 sparse vectors जनरेट करने की एक guide।</li>\n<li><a href=\"https://github.com/pinecone-io/pinecone-text\">Pinecone Text Repository on GitHub</a>: Pinecone का उपयोग करके text processing और vector generation resources का एक संग्रह।</li>\n<li><a href=\"https://www.pinecone.io/learn/hybrid-search-intro/\">Introduction to Hybrid Search on Pinecone's Website</a>: Pinecone की क्षमताओं के संदर्भ में hybrid search, इसके लाभों, और use cases का एक अवलोकन।</li>\n</ul>",
  "source_hash": "sha256:e66aaa4db1667d84e791217c8e94d2c0fb0ed99f7181b65b37a84e72ae3181ef",
  "model": "moonshotai/kimi-k2.6",
  "generated_at": "2026-08-07T05:25:05.691484+00:00"
}