Last active
May 10, 2022 20:41
-
-
Save davidmezzetti/b6030324eac8a9cf92c151500df3088e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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