Use this file to discover all available pages before exploring further.
Integration with Weaviate enables performing Retrieval Augmented Generation (RAG) directly within the Weaviate database.
This combines the power of Friendli Engine and Weaviate’s efficient storage and fast retrieval capabilities to generate personalized and context-aware responses.
Before you start, ensure you’ve already obtained the API_KEY from the Friendli Suite > Personal Settings > API Keys.
Also, set up your Weaviate instance following this guide.
Your Weaviate instance must be configured with the FriendliAI generative AI integration (generative-friendliai) module.
Now we can instantiate a Weaviate collection using our model.
We provide usage examples for each type of endpoint. Choose the one that best suits your needs.You can specify one of the available models for the serverless endpoints.
The default model (i.e. meta-llama-3.3-70b-instruct) will be used if no model is specified.
import weaviateimport osfrom weaviate.classes.init import Authfrom weaviate.classes.config import Configureheaders = { "X-Friendli-Api-Key": os.getenv("API_KEY"),}client = weaviate.connect_to_weaviate_cloud( cluster_url=weaviate_url, # `weaviate_url`: your Weaviate URL auth_credentials=Auth.api_key(weaviate_key), # `weaviate_key`: your Weaviate API Key headers=headers)client.collections.create( "DemoCollection", generative_config=Configure.Generative.friendliai( model = "meta-llama-3.3-70b-instruct", ) # Additional parameters not shown)client.close()
Configure the following generative parameters to customize the model behavior.
from weaviate.classes.config import Configureclient.collections.create( "DemoCollection", generative_config=Configure.Generative.friendliai( # These parameters are optional model = "meta-llama-3.3-70b-instruct", max_tokens = 500, temperature = 0.7, ))
To generate text for each object in the search results, use the single prompt method.
The example below generates outputs for each of the n search results, where n is specified by the limit parameter.When creating a single prompt query, use braces {} to interpolate the object properties you want Weaviate to pass on to the language model.
For example, to pass on the object’s title property, include {title} in the query.
collection = client.collections.get("DemoCollection")response = collection.generate.near_text( query="A holiday film", # The model provider integration will automatically vectorize the query single_prompt="Translate this into French: {title}", limit=2)for obj in response.objects: print(obj.properties["title"]) print(f"Generated output: {obj.generated}") # Note that the generated output is per object
To generate one text for the entire set of search results, use the grouped task method.
In other words, when you have n search results, the generative model generates one output for the entire group.
collection = client.collections.get("DemoCollection")response = collection.generate.near_text( query="A holiday film", # The model provider integration will automatically vectorize the query grouped_task="Write a fun tweet to promote readers to check out these films.", limit=2)print(f"Generated output: {response.generated}") # Note that the generated output is per queryfor obj in response.objects: print(obj.properties["title"])
Once the integrations are configured at the collection, the data management and search operations in Weaviate work identically to any other collection.
See the following model-agnostic examples: