Semantic Search
Semantic Search
bash
CopyEdit
conda create --name semantic_bert python=3.9 -y
conda activate semantic_bert
python
CopyEdit
from sentence_transformers import
SentenceTransformer
python
Tool Best For Key Strength
CopyEdit
from sklearn.neighbors import NearestNeighbors
python
CopyEdit
# Define a user query
query = "How does AI impact industries?"
# Display results
print("\nTop Search Results:")
for i, idx in enumerate(indices[0]):
print(f"{i+1}. {documents[idx]} (Score: {1 -
distances[0][i]})")
python
CopyEdit
Tool Best For Key Strength
from sklearn.metrics.pairwise import
cosine_similarity
Final Thoughts
Feature Implementation
Next Steps 🚀
Would you like help with integrating this into a web app? 🚀
You said:
another interesting sample for semantic search using above
ChatGPT said:
Let's build a semantic search system that allows users to search for
research papers based on their abstract or keywords. This is useful for
academic search engines, knowledge management systems, and AI-
powered document retrieval.
bash
CopyEdit
conda create --name semantic_research python=3.9 -y
conda activate semantic_research
Install Dependencies
bash
CopyEdit
pip install torch torchvision torchaudio
Tool Best For Key Strength
pip install sentence-transformers scikit-learn numpy
pandas
python
CopyEdit
import pandas as pd
print(df.head())
python
CopyEdit
from sentence_transformers import
SentenceTransformer
python
CopyEdit
from sklearn.neighbors import NearestNeighbors
Papers
Now, let's enter a query (e.g., "AI for chatbots") and retrieve the most
relevant papers.
python
CopyEdit
# Define a research query
query = "Conversational AI using deep learning"
# Perform search
distances, indices =
nn_model.kneighbors(query_vector)
✅ This will return the most contextually similar research papers based
on meaning rather than just keywords.
recomputing embeddings.
python
CopyEdit
queries = [
"How can we use AI in finance?",
"Quantum encryption methods",
"Reinforcement learning for automation"
]
📌 Final Thoughts
Feature Implementation