Hi @elie !
Considering the dataset you provided, this is how you can accomplish it:
import weaviate
from langchain.docstore.document import Document
from langchain.embeddings import OpenAIEmbeddings
from langchain_weaviate.vectorstores import WeaviateVectorStore
embeddings = OpenAIEmbeddings()
client = weaviate.connect_to_local()
docs = [
Document(
metadata={
"title": "Embracing The Future: AI Unveiled",
"author": "Dr. Rebecca Simmons",
},
page_content="A comprehensive analysis of the evolution of artificial intelligence, from its inception to its future prospects. Dr. Simmons covers ethical considerations, potentials, and threats posed by AI.",
),
Document(
metadata={
"title": "Symbiosis: Harmonizing Humans and AI",
"author": "Prof. Jonathan K. Sterling",
},
page_content="Prof. Sterling explores the potential for harmonious coexistence between humans and artificial intelligence. The book discusses how AI can be integrated into society in a beneficial and non-disruptive manner.",
),
Document(
metadata={"title": "AI: The Ethical Quandary", "author": "Dr. Rebecca Simmons"},
page_content="In her second book, Dr. Simmons delves deeper into the ethical considerations surrounding AI development and deployment. It is an eye-opening examination of the dilemmas faced by developers, policymakers, and society at large.",
),
Document(
metadata={
"title": "Conscious Constructs: The Search for AI Sentience",
"author": "Dr. Samuel Cortez",
},
page_content="Dr. Cortez takes readers on a journey exploring the controversial topic of AI consciousness. The book provides compelling arguments for and against the possibility of true AI sentience.",
),
Document(
metadata={
"title": "Invisible Routines: Hidden AI in Everyday Life",
"author": "Prof. Jonathan K. Sterling",
},
page_content="In his follow-up to 'Symbiosis', Prof. Sterling takes a look at the subtle, unnoticed presence and influence of AI in our everyday lives. It reveals how AI has become woven into our routines, often without our explicit realization.",
),
]
db = WeaviateVectorStore.from_documents(docs, embeddings, client=client, index_name="EliePoc")
query = db.similarity_search("polemic topic")
this is what I got inside query:
[Document(page_content='Dr. Cortez takes readers on a journey exploring the controversial topic of AI consciousness. The book provides compelling arguments for and against the possibility of true AI sentience.', metadata={'title': 'Conscious Constructs: The Search for AI Sentience', 'author': 'Dr. Samuel Cortez'}),
Document(page_content='In her second book, Dr. Simmons delves deeper into the ethical considerations surrounding AI development and deployment. It is an eye-opening examination of the dilemmas faced by developers, policymakers, and society at large.', metadata={'title': 'AI: The Ethical Quandary', 'author': 'Dr. Rebecca Simmons'}),
Document(page_content='A comprehensive analysis of the evolution of artificial intelligence, from its inception to its future prospects. Dr. Simmons covers ethical considerations, potentials, and threats posed by AI.', metadata={'title': 'Embracing The Future: AI Unveiled', 'author': 'Dr. Rebecca Simmons'}),
Document(page_content='Prof. Sterling explores the potential for harmonious coexistence between humans and artificial intelligence. The book discusses how AI can be integrated into society in a beneficial and non-disruptive manner.', metadata={'title': 'Symbiosis: Harmonizing Humans and AI', 'author': 'Prof. Jonathan K. Sterling'})]
You can also filter by your metadata, like so:
from weaviate.classes.query import Filter
filter = Filter.by_property("author").equal("Dr. Samuel Cortez")
query = db.similarity_search("polemic topic", filters=filter)
print(query)
this will yield, as expected, only the one object from your dataset:
[Document(page_content='Dr. Cortez takes readers on a journey exploring the controversial topic of AI consciousness. The book provides compelling arguments for and against the possibility of true AI sentience.', metadata={'title': 'Conscious Constructs: The Search for AI Sentience', 'author': 'Dr. Samuel Cortez'})]
Let me know if this helps.
Thanks!