@vectara/stream-query-client
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

Welcome to Stream-Query-Client

Stream-Query-Client

Stream-Query-Client is the easiest way to use Vectara's streaming query API in your JavaScript applications. Simply provide a query configuration and a callback to instantly receive stream updates.

[!TIP]

Looking for something else? Try another open-source project:

  • React-Search: Add Vectara semantic search to your React apps with a few lines of code.
  • React-Chatbot: Add a compact Vectara-powered chatbot widget chat to your React apps.
  • Create-UI: The fastest way to generate a working React codebase for a range of generative and semantic search UIs.
  • Vectara Answer: Demo app for Summarized Semantic Search with advanced configuration options.
  • Vectara Ingest: Sample templates and crawlers for pulling data from many popular data sources.

How it works

When executed, streamQuery sends a request to Vectara's streaming query API. As the endpoint returns data chunks to the browser, the supplied onStreamUpdate is executed with relevant data from the most recent chunk. You can then use this latest data in your application however you wish.

Use it in your application

Install Stream-Query-Client

npm install --save @vectara/stream-query-client

Then use it in your application like this:

import {
  streamQuery,
  StreamUpdate,
  StreamQueryConfig,
} from "@vectara/stream-query-client";

const sendQuery = async () => {
  const configurationOptions: StreamQueryConfig = {
    // Required fields.
    customerId: "customerIdValue",
    corpusIds: ["2"],
    apiKey: "zqt_apiKeyValue",

    // Optional fields.
    queryValue: "Who put the ram in the ramalamadingdong?",
    summaryNumResults: 5,
    language: "eng",
    debug: true,
    enableFactualConsistencyScore: true,
    summaryPromptName: "summary-prompt-name",
  };

  const onStreamUpdate = (update: StreamUpdate) => {
    // Perform operations on returned data, e.g. update state.
    console.log(update.updatedText);
  };

  streamQuery(configurationOptions, onStreamUpdate);
};

For more information on configuration options and callback types, see the type definitions and our Query API documentation.

License

Stream-Query-Client is an open-sourced software licensed under the Apache 2.0 license.

This repository contains sample code that can help you build UIs powered by Vectara, and is licensed under the Apache 2.0 License. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Readme

Keywords

none

Package Sidebar

Install

npm i @vectara/stream-query-client

Weekly Downloads

52

Version

2.0.2

License

Apache-2.0

Unpacked Size

1.58 MB

Total Files

33

Last publish

Collaborators

  • tallat
  • deryk-vectara
  • aamirbutt
  • ofermend
  • cjcenizal