Skip to main content
Version: Beta 🚧

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 source

  • vector_db_config (Any) - The vector store configuration

  • vectorize_column (str) - The column to vectorize

  • feature_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 tool

Example

from tecton_gen_ai.testing import make_local_source
from tecton_gen_ai.testing.utils import make_local_vector_db_config
df = [
{"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 source
from tecton_gen_ai.fco import source_as_knowledge
knowledge = 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 base
from tecton_gen_ai.fco import AgentService
service = AgentService(
"app",
knowledge=[knowledge],
)
# Test locally
from tecton_gen_ai.fco import AgentClient
client = AgentClient.from_local(service)
# search without filter
print(client.search("for_sale", query="fruit"))
# search with filter
print(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"}))

Was this page helpful?