0% found this document useful (0 votes)
25 views8 pages

Exa Search Engine

Uploaded by

sarthakjain1024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

Exa Search Engine

Uploaded by

sarthakjain1024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

BUILD A

CUSTOM

SEARCH ENGINE WITH EXA


SJ DAY 5
WHAT WE'LL CREATE
IS...

Picture this: You read a funny tweet (probably ours...), but


you forgot who tweeted it and where you saw it. You’re
sad. What if there was a search engine that rediscovers
exactly what you’re thinking about?
It's now possible with a specific kind of machine learning
called natural language processing (NLP).
In this tutorial, we'll build a custom search engine using an
API with LLM capabilities!🚀
Swipe
## EXA API
Exa (formerly "Metaphor") is an API (application programming
interface) that retrieves the best content on the web. With
Exa, anyone can semantically search the web to get high-
quality, relevant information. With Exa's technology, we can
rediscover the content on the internet. Unlike Google, which
relies on keyword search (matching the exact words of the
query to the web content), Exa can understand both the
user's input and the content out there. Wow, right?

# SET UP
Create an Exa account for an API key.
Install Python 3 and pip (if not already done).
In your code editor, create a main.py file.
Install the Exa package using:

bash

pip install exa_py

Swipe
# INITIALIZING THE API
python

from exa_py import Exa


exa = Exa('YOUR_KEY_HERE')
query = input('Search here: ')

MAKING A SEARCH
# REQUEST
Example of using Exa's .search() method:
python

response = exa.search(
'Best Chicago cold brew',
num_results=10,
)

Each result includes details like title, URL, and author.


To customize our Exa results further, we can play around
with Exa's filters to find the exact type of content we need.
You can explore the filters here Exa's API Search
documentation ( https://docs.exa.ai/reference/search )

Swipe
# CUSTOMIZING SEARCHES
You can fine-tune searches using filters, such as:
numResults: Limit number of results.
includeDomains: Limit search to specified domains.
category: Search specific content types (e.g., tweets,
papers).

The search example below will return 10 results for "best


pizza in Brooklyn" searching through Twitter since May
2023:
python

response = exa.search(
'best pizza in Brooklyn',
num_results=10,
start_published_date='2023-05-01',
category='tweet',
use_autoprompt=True,
)

# SEARCH COFFEE ON
TIKTOK

Swipe
This is where the fun customization begins! ✨💖
For this tutorial, you'll learn how to search TikTok to obtain
top coffee drink accounts!
python

from exa_py import Exa


exa = Exa('YOUR_KEY_HERE')
query = input('Search here: ')
response = exa.search(
query,
num_results=5,
type='keyword',
include_domains=['https://www.tiktok.com'],
)
print(response)

Run the script by going to your terminal and typing:


python

python3 main.py

After pressing enter, you should now see the following:

Swipe
Let's format our code so that for our React documentation
search engine, we only get the Title and the URL. Delete the
print statement, and add the following to main.py.
python

for result in response.results:


print(f'Title: {result.title}')
print(f'URL: {result.url}')
print()

Now, your search results should look something like this!

A lot easier on the eyes, right? 🤩💫

Swipe
MISSION
ACCOMPLISHED!
#
Congrats, you just created a custom search engine! ✨
Here are some additional ideas on what you could search with the
Exa API!
Wikipedia links
Coding documentation
Academic papers
Tweets
Research papers
News and media

# Don’t Forget to visit the github repo.


for the code.
http://github.com/iamSarthak2002

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy