Notebooks
N
Neode
03 Semantic Search

03 Semantic Search

neode-notebookstutorials

šŸ” Semantic Search

Open in Alph

This cookbook covers how to search your knowledge graph using natural language queries.

What You'll Learn

  • Performing semantic searches with natural language
  • Understanding similarity scores
  • Building Q&A functions over your knowledge graph
[ ]

Setup: Create Sample Knowledge Base

Let's populate our knowledge graph with some data to search:

[16]
āœ… Created 24 triples for our tech knowledge base!

Basic Semantic Search

Search using natural language - Neode understands the meaning behind your query:

[17]
šŸ” Query: 'Who founded Apple?'
--------------------------------------------------

šŸ“Œ Matching Entities:
  Apple Inc (similarity: 0.6434)
  Steve Jobs (similarity: 0.4919)
  Google (similarity: 0.4489)
  Microsoft (similarity: 0.4449)
  Bill Gates (similarity: 0.3149)

šŸ”— Matching Triples:
  Apple Inc → founded_by → Steve Jobs (similarity: 0.7714)
  Apple Inc → founded_by → Steve Wozniak (similarity: 0.7369)
  Apple Inc → founded_in → 1976 (similarity: 0.6492)
  Apple Inc → produces → iPhone (similarity: 0.5513)
  Steve Jobs → is_a → entrepreneur (similarity: 0.5216)
[19]

šŸ” Query: 'What products does Apple make?'
--------------------------------------------------
  Apple Inc → produces → iPhone
  Apple Inc → produces → MacBook
  Apple Inc → industry → consumer electronics

šŸ” Query: 'Where is Microsoft located?'
--------------------------------------------------
  Microsoft → headquartered_in → Redmond, Washington
  Microsoft → founded_in → 1975
  Microsoft → founded_by → Paul Allen

šŸ” Query: 'Tell me about Bill Gates'
--------------------------------------------------
  Bill Gates → is_a → entrepreneur
  Bill Gates → is_a → philanthropist
  Microsoft → founded_by → Bill Gates

šŸ” Query: 'Which founders went to Stanford?'
--------------------------------------------------
  Larry Page → studied_at → Stanford University
  Sergey Brin → studied_at → Stanford University
  Google → founded_by → Sergey Brin

šŸ” Query: 'Companies in California'
--------------------------------------------------
  Google → parent_company → Alphabet Inc
  Google → headquartered_in → Mountain View, California
  Apple Inc → headquartered_in → Cupertino, California

Semantic Search with GET Method

You can also use the GET endpoint for simpler queries:

[20]
šŸ” Query: 'technology entrepreneurs'
--------------------------------------------------

šŸ“Œ Matching Entities:
  Bill Gates (similarity: 0.5770)
  Steve Jobs (similarity: 0.5346)
  Larry Page (similarity: 0.4131)
  Google (similarity: 0.3645)
  Sergey Brin (similarity: 0.3637)

šŸ”— Matching Triples:
  Bill Gates → is_a → entrepreneur
  Steve Jobs → is_a → entrepreneur
  Google → founded_by → Larry Page
  Google → founded_by → Sergey Brin
  Bill Gates → is_a → philanthropist
  Microsoft → founded_by → Bill Gates
  Google → founded_in → 1998
  Larry Page → studied_at → Stanford University
  Microsoft → founded_by → Paul Allen
  Sergey Brin → studied_at → Stanford University

Building a Simple Q&A Function

[21]
ā“ When was Google founded?
Based on the knowledge graph:
• Google founded in 1998
• Google founded by Sergey Brin
• Google founded by Larry Page
• Microsoft founded in 1975
• Google headquartered in Mountain View, California

ā“ What does Microsoft make?
Based on the knowledge graph:
• Microsoft produces Windows
• Microsoft founded by Bill Gates
• Microsoft founded in 1975
• Microsoft headquartered in Redmond, Washington
• Microsoft founded by Paul Allen

ā“ Who are famous entrepreneurs?
Based on the knowledge graph:
• Steve Jobs is a entrepreneur
• Bill Gates is a entrepreneur
• Bill Gates is a philanthropist
• Google founded by Sergey Brin
• Google founded by Larry Page

Combining Search with Analysis

[22]
šŸ“Š Search Results Analysis:
Total results: 20

Unique subjects: ['Google', 'Microsoft', 'Steve Jobs', 'Bill Gates', 'Apple Inc', 'Sergey Brin', 'Larry Page']

Relationship types found:
predicate
founded_by          6
founded_in          3
is_a                3
produces            3
studied_at          2
parent_company      1
industry            1
headquartered_in    1
Name: count, dtype: int64

Next Steps

  • 04_ai_triple_generation.ipynb - Automatically generate triples from text
  • 05_graphs_and_entities.ipynb - Organize knowledge into separate graphs