![]() ![]() ![]() You can pass the boolean values true and false easily to Javascript. You can pass the number 1 very easily to Javascript. You can pass the string "foo" very easily to Javascript. PHP and Javascript can only communicate via strings. Take for example this common problem: How do I pass a PHP array to Javascript? There are many other formats though, like JSON or XML. The standard PHP function serialize is just a format to express such a thing, it serializes a data structure into a string representation that's unique to PHP and can be reversed into a PHP object using unserialize. That just means to put the structure into a "lower common denominator" that can be handled by things other than PHP, like databases, text files, sockets. If you want to persist such a complex data structure beyond a single run of a script, you need to serialize it. Gets the data repository in write modeįor (session in DroidconSessionData.A PHP array or object or other complex data structure cannot be transported or stored or otherwise used outside of a running PHP script. The second half of the snippet adds the database customization – first the vector (which is an array of Double values) gets serialized, and then it is inserted into the database using the dbHelper class that has been added to the function: In Figure 2, you can see the first half of the code snippet has not changed – it still loops through the conference schedule and generates an embedding for each session via the web API. The updated code leverages this existing loop to also insert each vector into the local database.Īs mentioned above, there are no special vector-handling features in the existing version of Sqlite, so the code will treat the vector as a string for data storage and retrieval. There is already an initVectorCache function in the DroidconEmbeddingsWrapper.kt file which generates all the vectors in a loop over the droidconSessions collection and stores the vectors in-memory in the vectorCache variable. The DroidconDbHelper then takes care of creating the table (don’t forget to update the DATABASE_VERSION whenever you make schema changes). Private const val SQL_CREATE_EMBEDDING_ENTRIES = The schema and create/delete scripts for an embeddings table are defined in the data/DroidconDatabase.kt file:Ĭonst val COLUMN_NAME_SESSIONID = "session_id" The database setup uses the same pattern that we used for the favorites feature. ![]() Don’t forget to choose the droidcon-chat from the top-left menu to test out these features.įigure 1: Embeddings with similarity comparisons enable retrieval augmented generation (RAG) chat interactions Configure the database The sample code is available at /conceptdev/droidcon-sf-23. The demo app we’re working on is the JetchatAI sample that allows you to query the conference schedule for the droidcon SF 2023 event. Embedding vector similarity comparisons will continue to be done with the dot function defined in DroidconEmbeddingsWrapper.kt. Note that the version of Sqlite we’ll use on Android does not have any special “vector database” features – instead, the embedding vectors will just be serialized/deserialized and stored in a TEXT column. Now that we’ve added Sqlite to the solution to support memory and querying, we can use that infrastructure to also cache the embedding vectors. Earlier this year I tried to create a hardcoded cache of embedding vectors, only to be thwarted by the limitations of Kotlin (the combined size of the arrays of numbers exceeded Kotlin’s maximum function size). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |