Functions
source_as_knowledge​
Convert a Tecton data source to a knowledge base. This function will create an ingestion pipeline to vectorize the data source and store it to the designated vector store. It will also create a real-time search tool to search the knowledge base.Parameters
source
(Union
[DataSource
,FilteredSource
]) - The data sourcevector_db_config
(Any
) - The vector store configurationvectorize_column
(str
) - The column to vectorizefeature_start_time
(Optional
[datetime.datetime
]) - The feature start time, defaults to None. When None, it requires the source to be a mock source created for testing purpose. Default:None
batch_schedule
(timedelta
) - The batch schedule, defaults to timedelta(days=1) Default:1 day, 0:00:00
timestamp_field
(Optional
[str
]) - The timestamp field, defaults to None. When None, it requires the source to be a mock source created for testing purpose. Default:None
name
(Optional
[str
]) - The name of the knowledge base, defaults to None. When None, it will use the name of the source. Default:None
description
(Optional
[str
]) - The description of the knowledge base, defaults to None. When None, it will use the description of the source. Default:None
filter
(Optional
[List
[Tuple
[str
,Any
,str
]]]) - The vector db metadata filter fields, defaults to None. The format is a list of tuples (column_name, data_type, description). Default:None
ingestion_kwargs
(Optional
[Dict
[str
,Any
]]) - The ingestion (batch feature view) kwargs, defaults to None. Default:None
serving_kwargs
(Optional
[Dict
[str
,Any
]]) - The serving (real-time feature view) kwargs, defaults to None. Default:None
Returns
Any
: The batch feature view and the search toolExample
from tecton_gen_ai.testing import make_local_sourcefrom tecton_gen_ai.testing.utils import make_local_vector_db_configdf = [{"zip":"98005", "item_id":1, "description":"pencil"},{"zip":"98005", "item_id":2, "description":"car"},{"zip":"98005", "item_id":3, "description":"paper"},{"zip":"10065", "item_id":4, "description":"boat"},{"zip":"10065", "item_id":5, "description":"cheese"},{"zip":"10065", "item_id":6, "description":"apple"},]src = make_local_source("for_sale",df,description="Items information", # required for source_as_knowledge)vdb_conf = make_local_vector_db_config()# Create a knowledge base from the sourcefrom tecton_gen_ai.fco import source_as_knowledgeknowledge = source_as_knowledge(src,vector_db_config=vdb_conf,vectorize_column="description",filter = [("zip", str, "the zip code of the item for sale")])# Serve the knowledge basefrom tecton_gen_ai.fco import AgentServiceservice = AgentService("app",knowledge=[knowledge],)# Test locallyfrom tecton_gen_ai.fco import AgentClientclient = AgentClient.from_local(service)# search without filterprint(client.search("for_sale", query="fruit"))# search with filterprint(client.search("for_sale", query="fruit", top_k=3, filter={"zip": "27001"}))print(client.search("for_sale", query="fruit", top_k=3, filter={"zip": "10065"}))