Skip to content
prashant7090Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Data:

https://www.kaggle.com/datasets/hgultekin/bbcnewsarchive

Content Consists of 2225 documents from the BBC news website corresponding to stories in five topical areas from 2004-2005. Class Labels: 5 (business, entertainment, politics, sport, tech)

BBC News Semantic Search with Neo4j Vector Index

Overview

This project builds a local semantic search system using:

  • Neo4j as the graph database
  • Sentence Transformers for local embeddings
  • Neo4j Vector Index for similarity search

The goal is to search BBC News articles by meaning, not only by exact keywords.

Example:

Instead of searching only for:

profit

you can ask:

Companies reporting financial growth

and retrieve articles related to revenue growth, advertising performance, and business success.


Architecture

                 User Query
                     |
                     v
          Sentence Transformer Model
             (all-MiniLM-L6-v2)
                     |
                     v
              Query Embedding
              (384 dimensions)
                     |
                     v
            Neo4j Vector Index
                     |
                     v
          Similar Article Embeddings
                     |
                     v
             Relevant Articles

Dataset

Source:

BBC News Dataset

Columns:

Column Description
category News category
filename Original file name
title Article title
content Article text

Example:

business | 001.txt | Ad sales boost Time Warner profit | Quarterly profits...

Neo4j Data Model

Nodes

Article

Properties:

Article
├── category
├── filename
├── title
├── content
└── embedding

embedding contains a 384-dimensional vector generated by the embedding model.

Category

Properties:

Category
└── name

Relationship

(Article)-[:BELONGS_TO]->(Category)

Neo4j Constraints

Created constraints:

CREATE CONSTRAINT article_identity IF NOT EXISTS
FOR (a:Article)
REQUIRE (a.category, a.filename) IS UNIQUE;
CREATE CONSTRAINT category_name_unique IF NOT EXISTS
FOR (c:Category)
REQUIRE c.name IS UNIQUE;

Environment Setup

Create Python environment

python3 -m venv venv

Activate:

source venv/bin/activate

Install dependencies:

pip install sentence-transformers neo4j tqdm

Generate Embeddings

File:

generate_embeddings.py

Purpose:

  1. Connect to Neo4j.
  2. Read all Article nodes.
  3. Combine:
title + content
  1. Generate embeddings using:
all-MiniLM-L6-v2
  1. Store vectors:
Article.embedding

Run:

python generate_embeddings.py

Validation:

MATCH (a:Article)
WHERE a.embedding IS NOT NULL
RETURN count(a);

Check vector size:

MATCH (a:Article)
RETURN size(a.embedding)
LIMIT 1;

Expected:

384

Vector Index

Create Neo4j vector index:

CREATE VECTOR INDEX article_embeddings IF NOT EXISTS
FOR (a:Article)
ON (a.embedding)
OPTIONS {
    indexConfig: {
        `vector.dimensions`: 384,
        `vector.similarity_function`: 'cosine'
    }
};

Semantic Search

File:

semantic_search.py

Purpose:

  1. Accept user question.
  2. Convert question into embedding.
  3. Search Neo4j vector index.
  4. Return similar articles.

Example:

Input:

Companies reporting financial growth

Output:

Title:
Ad sales boost Time Warner profit

Category:
business

Similarity Score:
0.82

How Semantic Search Works

Stored article:

TimeWarner profits increased because of advertising sales

gets converted into:

[0.12, -0.31, 0.44 ...]

User query:

Companies reporting financial growth

gets converted into:

[0.10, -0.29, 0.41 ...]

Neo4j compares the vectors using cosine similarity and returns the closest matches.


Technologies

  • Neo4j
  • Python
  • Sentence Transformers
  • all-MiniLM-L6-v2
  • Vector Search

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages