Quantcast
Channel: Pinecone Community - Latest topics
Viewing all articles
Browse latest Browse all 832

Building RAG with Pinecone on Android/Kotlin

$
0
0

Hi everyone, I built the prototype for my client in Python. Pinecone is so solid. Now I am releasing the solution on mobile, starting with Android/Kotlin. On mobile, we just don’t have the resources available like in the Python world. Here’s my Kotlin general API query function. Does anyone have any good Pinecone libraries to make implementing Pinecone easier on mobile? I am using OKhttp an GSON with good results.

// get embeddings from pinecone vector database

suspend fun queryPinecone(vector: List<Double>, topK: Int = 3): String = withContext(Dispatchers.IO) {
    val indexName = "your-index"
    val project = "your-project"
    val environment = "your-enviro"
    val namespace = "your_ns"

​    val jsonPayload = Gson().toJson(
​        mapOf(
​            "vector" to vector,
​            "topK" to topK,
​            "namespace" to namespace,
​            "includeValues" to false,
​            "includeMetadata" to true
​        )
​    )
​    val requestBody = jsonPayload.toRequestBody("application/json; charset=utf-8".toMediaType())
​    val request = Request.Builder()
​        .url("https://${indexName}-${project}.svc.${environment}.pinecone.io/query")
​        .addHeader("Api-Key", your_api-key)
​        .post(requestBody)
​        .build()

​    client.newCall(request).execute().use { response ->
​        if (!response.isSuccessful) {
​            val errorBody = response.body?.string()
​            val errorMessage = "PC API call failed: ${response.code}: $errorBody"
​            Log.e("MyAppTag", errorMessage)
​            throw Exception(errorMessage)
​        }
​        response.body?.string() ?: ""
​    }
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 832

Trending Articles