Skip to content

embeddings.search hangs indefinitely on Mac #576

@tf13

Description

@tf13

Running OS 12.7 (Monterrey) on a MacBook Air (M1, 2020) with Python 3.11.5

Script below — it should be effectively identical to the first example at https://neuml.hashnode.dev/tutorial-series-on-txtai

It failed in Spyder and also from the command line in Terminal (both with python3 scriptname.py and line by line after running python3 on the command line).

I then tried the same script on an Linux box I have access to, running Ubuntu 22.04.3 LTS. It worked fine as-is from the command line.

from txtai import Embeddings

# temp data
data = [
  "US tops 5 million confirmed virus cases",
  "Canada's last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg",
  "Beijing mobilises invasion craft along coast as Taiwan tensions escalate",
  "The National Park Service warns against sacrificing slower friends in a bear attack",
  "Maine man wins $1M from $25 lottery ticket",
  "Make huge profits without work, earn up to $100,000 a day"
]

# create embeddings
embeddings = Embeddings(path="sentence-transformers/nli-mpnet-base-v2")

# create index for list of texts
embeddings.index(data)

print(f"{'Query':20} Best Match")
print("-" * 50)


for query in ("feel good story", "climate change", "public health story", "war",
              "wildlife", "asia", "lucky", "dishonest junk"):
    # Extract uid of first result
    # search result format: (uid, score)
    uid = embeddings.search(query)[0][0]

    # Print text
    print(f"{query:20} {data[uid]}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions