Quantcast
Channel: Weaviate Community Forum - Latest posts
Viewing all articles
Browse latest Browse all 3588

How to load existing db to similarity search?

$
0
0

This is because it will only use text_key on ingestion.

Take this, for example:

# single insertion
from langchain_openai import OpenAIEmbeddings
from langchain_weaviate.vectorstores import WeaviateVectorStore

from langchain.schema import Document

embeddings = OpenAIEmbeddings()
doc1 = Document(
    page_content="this is the page content",
    metadata={"metadata1": "something", "metadata2": "other thing"}
)
db = WeaviateVectorStore.from_documents([doc1], embeddings, client=client, index_name="TestCollection")
print(client.collections.get("TestCollection").query.fetch_objects().objects[0].properties)

this will print:

{‘text’: ‘this is the page content’,
‘metadata2’: ‘other thing’,
‘metadata1’: ‘something’}

now if we change text_key, this is what will happen:

db = WeaviateVectorStore.from_documents([doc1], embeddings, client=client, index_name="TestCollection2", text_key="text_goes_here")
print(client.collections.get("TestCollection2").query.fetch_objects().objects[0].properties)

and the output:

{‘metadata2’: ‘other thing’,
‘text_goes_here’: ‘this is the page content’,
‘metadata1’: ‘something’}

Note that, as you passed some metadata (and changed the text_key), you can now use the hybrid weights to lean your query towards a specific metadata field.

When you are specifying the query properties, you will need to specify the very same text_key that you set for your collection.

For example, is you set text_key as text_goes_here:

db.similarity_search("thing", query_properties=["text_goes_here", "metadata1^2", "metadata2"])

if you don’t provide a query_properties at query time, Weaviate will look into all searchable properties.

More on setting hybrid query weights on property values here:

Let me know if this helps!


Viewing all articles
Browse latest Browse all 3588

Trending Articles