Skip to content

Instantly share code, notes, and snippets.

@davidmezzetti
Last active May 10, 2022 20:41
Show Gist options
  • Save davidmezzetti/b6030324eac8a9cf92c151500df3088e to your computer and use it in GitHub Desktop.
Save davidmezzetti/b6030324eac8a9cf92c151500df3088e to your computer and use it in GitHub Desktop.
# pip install spacy --upgrade
# python -m spacy download en_core_web_md
import spacy
# Load spacy
nlp = spacy.load("en_core_web_md")
def transform(inputs):
return [result.vector for result in nlp.pipe(inputs)]
# Index data with spacy pipeline
embeddings = Embeddings({"method": "external", "transform": transform, "content": True})
embeddings.index([(uid, text, None) for uid, text in enumerate(data)])
# Run search
print(embeddings.search("select id, text, score from txtai where similar('nature')", 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment